package com.ctshk.rpc.booking.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.*;
import com.ctshk.common.exception.BusinessException;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.utils.EntityUtil;
import com.ctshk.common.utils.SnowflakeIdWorker;
import com.ctshk.common.utils.ValidatorUtil;
import com.ctshk.rpc.booking.dto.*;
import com.ctshk.rpc.booking.dto.outside.SupplierOrderOutsidePageDTO;
import com.ctshk.rpc.booking.dto.outside.admission.query.SupplierOrderAdmissionDTO;
import com.ctshk.rpc.booking.dto.outside.admission.query.SupplierOutsideOrderAdmissionTicketDTO;
import com.ctshk.rpc.booking.dto.outside.air.query.SupplierOrderAirDTO;
import com.ctshk.rpc.booking.dto.outside.air.query.SupplierOutsideOrderAirDTO;
import com.ctshk.rpc.booking.dto.outside.car.query.SupplierOrderCarDTO;
import com.ctshk.rpc.booking.dto.outside.car.query.SupplierOutsideOrderCarRentalDTO;
import com.ctshk.rpc.booking.dto.outside.food.query.SupplierOrderFoodDTO;
import com.ctshk.rpc.booking.dto.outside.food.query.SupplierOutsideOrderFoodDTO;
import com.ctshk.rpc.booking.dto.outside.hotel.query.SupplierOrderHotelDTO;
import com.ctshk.rpc.booking.dto.outside.hotel.query.SupplierOutsideOrderHotelCheckInDTO;
import com.ctshk.rpc.booking.dto.outside.other.query.SupplierOrderOtherDTO;
import com.ctshk.rpc.booking.dto.outside.other.query.SupplierOutsideOrderOtherDTO;
import com.ctshk.rpc.booking.dto.outside.ship.query.SupplierOrderShipDTO;
import com.ctshk.rpc.booking.dto.outside.ship.query.SupplierOutsideOrderShipDTO;
import com.ctshk.rpc.booking.dto.outside.train.query.SupplierOrderTrainDTO;
import com.ctshk.rpc.booking.dto.outside.train.query.SupplierOutsideOrderTrainDTO;
import com.ctshk.rpc.booking.dto.system.admission.info.SupplierOrderSystemAdmissionInfoDTO;
import com.ctshk.rpc.booking.dto.system.admission.info.SupplierSystemOrderAdmissionTicketInfoDTO;
import com.ctshk.rpc.booking.dto.system.admission.page.SupplierOrderAdmissionPageDTO;
import com.ctshk.rpc.booking.dto.system.air.info.SupplierOrderSystemAirInfoDTO;
import com.ctshk.rpc.booking.dto.system.air.info.SupplierSystemOrderAirInfoDTO;
import com.ctshk.rpc.booking.dto.system.air.page.SupplierOrderAirPageDTO;
import com.ctshk.rpc.booking.dto.system.airexpress.info.SupplierOrderSystemAirExpressInfoDTO;
import com.ctshk.rpc.booking.dto.system.airexpress.info.SupplierSystemOrderAirExpressInfoDTO;
import com.ctshk.rpc.booking.dto.system.airexpress.page.SupplierOrderAirExpressPageDTO;
import com.ctshk.rpc.booking.dto.system.bus.info.SupplierOrderSystemBusInfoDTO;
import com.ctshk.rpc.booking.dto.system.bus.info.SupplierSystemOrderBusInfoDTO;
import com.ctshk.rpc.booking.dto.system.bus.page.SupplierOrderBusPageDTO;
import com.ctshk.rpc.booking.dto.system.commodity.info.SupplierOrderSystemCommodityInfoDTO;
import com.ctshk.rpc.booking.dto.system.commodity.info.SupplierSystemOrderCommodityInfoDTO;
import com.ctshk.rpc.booking.dto.system.commodity.page.SupplierOrderCommodityPageDTO;
import com.ctshk.rpc.booking.dto.system.hotel.info.SupplierOrderSystemHotelInfoDTO;
import com.ctshk.rpc.booking.dto.system.hotel.info.SupplierSystemOrderHotelCheckInInfoDTO;
import com.ctshk.rpc.booking.dto.system.hotel.page.SupplierOrderHotelPageDTO;
import com.ctshk.rpc.booking.dto.system.insurance.info.SupplierOrderSystemInsuranceInfoDTO;
import com.ctshk.rpc.booking.dto.system.insurance.info.SupplierSystemOrderInsuranceInfoDTO;
import com.ctshk.rpc.booking.dto.system.insurance.page.SupplierOrderInsurancePageDTO;
import com.ctshk.rpc.booking.dto.system.localfun.info.SupplierOrderSystemLocalFunInfoDTO;
import com.ctshk.rpc.booking.dto.system.localfun.info.SupplierSystemOrderLocalFunInfoDTO;
import com.ctshk.rpc.booking.dto.system.localfun.page.SupplierOrderLocalFunPageDTO;
import com.ctshk.rpc.booking.dto.system.ship.info.SupplierOrderSystemShipInfoDTO;
import com.ctshk.rpc.booking.dto.system.ship.info.SupplierSystemOrderShipInfoDTO;
import com.ctshk.rpc.booking.dto.system.ship.page.SupplierOrderShipPageDTO;
import com.ctshk.rpc.booking.dto.system.stampduty.info.SupplierOrderSystemStampDutyInfoDTO;
import com.ctshk.rpc.booking.dto.system.stampduty.info.SupplierSystemOrderStampDutyInfoDTO;
import com.ctshk.rpc.booking.dto.system.stampduty.page.SupplierOrderStampDutyPageDTO;
import com.ctshk.rpc.booking.dto.system.train.info.SupplierOrderSystemTrainInfoDTO;
import com.ctshk.rpc.booking.dto.system.train.info.SupplierSystemOrderTrainInfoDTO;
import com.ctshk.rpc.booking.dto.system.train.page.SupplierOrderTrainPageDTO;
import com.ctshk.rpc.booking.dto.system.visa.info.SupplierOrderSystemVisaInfoDTO;
import com.ctshk.rpc.booking.dto.system.visa.info.SupplierSystemOrderVisaInfoDTO;
import com.ctshk.rpc.booking.dto.system.visa.page.SupplierOrderVisaPageDTO;
import com.ctshk.rpc.booking.entity.SupplierOrder;
import com.ctshk.rpc.booking.entity.SupplierSystemOrderHotelCheckIn;
import com.ctshk.rpc.booking.enums.SupplierCheckStatus;
import com.ctshk.rpc.booking.enums.SupplierPaymentStatus;
import com.ctshk.rpc.booking.enums.SupplierReserveTypeEnum;
import com.ctshk.rpc.booking.enums.SupplierVerifyStatusEnum;
import com.ctshk.rpc.booking.mapper.*;
import com.ctshk.rpc.booking.req.SupplierOrderFinancePageReq;
import com.ctshk.rpc.booking.req.SupplierOrderFinishPageReq;
import com.ctshk.rpc.booking.req.SupplierOrderPageReq;
import com.ctshk.rpc.booking.req.SupplierOrderUnsubBookingPageReq;
import com.ctshk.rpc.booking.req.outside.SupplierOrderOutsidePageReq;
import com.ctshk.rpc.booking.req.outside.admission.save.SupplierOrderOutsideAdmissionSaveReq;
import com.ctshk.rpc.booking.req.outside.air.save.SupplierOrderOutsideAirSaveReq;
import com.ctshk.rpc.booking.req.outside.approval.SupplierOrderOutsideApprovalReq;
import com.ctshk.rpc.booking.req.outside.car.save.SupplierOrderOutsideCarSaveReq;
import com.ctshk.rpc.booking.req.outside.food.save.SupplierOrderOutsideFoodSaveReq;
import com.ctshk.rpc.booking.req.outside.hotel.save.SupplierOrderOutsideHotelSaveReq;
import com.ctshk.rpc.booking.req.outside.other.save.SupplierOrderOutsideOtherSaveReq;
import com.ctshk.rpc.booking.req.outside.ship.save.SupplierOrderOutsideShipSaveReq;
import com.ctshk.rpc.booking.req.outside.train.save.SupplierOrderOutsideTrainSaveReq;
import com.ctshk.rpc.booking.req.system.SupplierOrderSystemConfirmReq;
import com.ctshk.rpc.booking.req.system.SupplierOrderSystemFreeCallConfirmReq;
import com.ctshk.rpc.booking.req.system.SystemConfirmReq;
import com.ctshk.rpc.booking.req.system.admission.add.SupplierOrderSystemAdmissionAddReq;
import com.ctshk.rpc.booking.req.system.admission.edit.SupplierOrderSystemAdmissionEditReq;
import com.ctshk.rpc.booking.req.system.admission.page.SupplierOrderSystemAdmissionPageReq;
import com.ctshk.rpc.booking.req.system.air.add.SupplierOrderSystemAirAddReq;
import com.ctshk.rpc.booking.req.system.air.edit.SupplierOrderSystemAirEditReq;
import com.ctshk.rpc.booking.req.system.air.page.SupplierOrderSystemAirPageReq;
import com.ctshk.rpc.booking.req.system.airexpress.add.SupplierOrderSystemAirExpressAddReq;
import com.ctshk.rpc.booking.req.system.airexpress.page.SupplierOrderSystemAirExpressPageReq;
import com.ctshk.rpc.booking.req.system.bus.add.SupplierOrderSystemBusAddReq;
import com.ctshk.rpc.booking.req.system.bus.edit.SupplierOrderSystemBusEditReq;
import com.ctshk.rpc.booking.req.system.bus.page.SupplierOrderSystemBusPageReq;
import com.ctshk.rpc.booking.req.system.commodity.add.SupplierOrderSystemCommodityAddReq;
import com.ctshk.rpc.booking.req.system.commodity.edit.SupplierOrderSystemCommodityEditReq;
import com.ctshk.rpc.booking.req.system.commodity.page.SupplierOrderSystemCommodityPageReq;
import com.ctshk.rpc.booking.req.system.hotel.add.SupplierOrderSystemHotelAddReq;
import com.ctshk.rpc.booking.req.system.hotel.edit.SupplierOrderSystemHotelEditReq;
import com.ctshk.rpc.booking.req.system.hotel.edit.SupplierSystemOrderHotelCheckInEditReq;
import com.ctshk.rpc.booking.req.system.hotel.page.SupplierOrderSystemHotelPageReq;
import com.ctshk.rpc.booking.req.system.insurance.add.SupplierOrderSystemInsuranceAddReq;
import com.ctshk.rpc.booking.req.system.insurance.page.SupplierOrderSystemInsurancePageReq;
import com.ctshk.rpc.booking.req.system.localfun.add.SupplierOrderSystemLocalFunAddReq;
import com.ctshk.rpc.booking.req.system.localfun.edit.SupplierOrderSystemLocalFunEditReq;
import com.ctshk.rpc.booking.req.system.localfun.page.SupplierOrderSystemLocalFunPageReq;
import com.ctshk.rpc.booking.req.system.ship.add.SupplierOrderSystemShipAddReq;
import com.ctshk.rpc.booking.req.system.ship.edit.SupplierOrderSystemShipEditReq;
import com.ctshk.rpc.booking.req.system.ship.page.SupplierOrderSystemShipPageReq;
import com.ctshk.rpc.booking.req.system.stampduty.add.SupplierOrderSystemStampDutyAddReq;
import com.ctshk.rpc.booking.req.system.stampduty.page.SupplierOrderSystemStampDutyPageReq;
import com.ctshk.rpc.booking.req.system.train.add.SupplierOrderSystemTrainAddReq;
import com.ctshk.rpc.booking.req.system.train.edit.SupplierOrderSystemTrainEditReq;
import com.ctshk.rpc.booking.req.system.train.page.SupplierOrderSystemTrainPageReq;
import com.ctshk.rpc.booking.req.system.visa.add.SupplierOrderSystemVisaAddReq;
import com.ctshk.rpc.booking.req.system.visa.edit.SupplierOrderSystemVisaEditReq;
import com.ctshk.rpc.booking.req.system.visa.page.SupplierOrderSystemVisaPageReq;
import com.ctshk.rpc.booking.service.*;
import com.ctshk.rpc.finance.req.supplier.SupplierReconciliationAmountDTO;
import com.ctshk.rpc.finance.service.IFinanceSupplierReconciliationService;
import com.ctshk.rpc.hotel.service.IHotelOrderService;
import com.ctshk.rpc.order.air.req.SupplierConfirmOrderReq;
import com.ctshk.rpc.order.air.service.IAirOrderService;
import com.ctshk.rpc.order.bus.req.BusOrderSupplieConfirmReq;
import com.ctshk.rpc.order.bus.service.IBusOrderService;
import com.ctshk.rpc.order.hotel.service.IHotelOrderCenterService;
import com.ctshk.rpc.order.localfun.service.ILocalFunOrderService;
import com.ctshk.rpc.order.scenic.dto.ProductTicketDTO;
import com.ctshk.rpc.order.scenic.req.ConfirmProductTickeReq;
import com.ctshk.rpc.order.scenic.service.IScenicOrderService;
import com.ctshk.rpc.order.ship.service.IShipOrderService;
import com.ctshk.rpc.order.train.service.ITrainOrderService;
import com.ctshk.rpc.system.dto.MainDataCurrencyQueryDTO;
import com.ctshk.rpc.system.dto.QuerySupplierCostItemDTO;
import com.ctshk.rpc.system.dto.UserDTO;
import com.ctshk.rpc.system.req.MainDataCurrencyUpdateStatusReq;
import com.ctshk.rpc.system.req.QuerySupplierCostItemReq;
import com.ctshk.rpc.system.service.IMainDataCurrencyService;
import com.ctshk.rpc.system.service.ISysDepartmentService;
import com.ctshk.rpc.system.service.ISysSupplierCostItemService;
import com.ctshk.rpc.system.service.ISysUserService;
import com.ctshk.rpc.visa.req.visa.VisaOrderSupplieConfirmReq;
import com.ctshk.rpc.visa.service.IVisaOrderService;
import com.ctshk.rpc.workflow.dto.ApprovalCheckDTO;
import com.ctshk.rpc.workflow.dto.ApprovalStartDTO;
import com.ctshk.rpc.workflow.service.ISysApprovalService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static com.ctshk.rpc.booking.Constants.*;

/**
 * <p>
 * 统一供应商预订单 服务实现类
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-03-09
 */
@Slf4j
@DubboService
public class SupplierOrderServiceImpl implements ISupplierOrderService {
    @Autowired
    SupplierOrderMapper supplierOrderMapper;
    @Autowired
    SupplierOutsideOrderAirMapper supplierOutsideOrderAirMapper;
    @Autowired
    SupplierOutsideOrderTrainMapper supplierOutsideOrderTrainMapper;
    @Autowired
    SupplierOutsideOrderShipMapper supplierOutsideOrderShipMapper;
    @Autowired
    SupplierOutsideOrderFoodMapper supplierOutsideOrderFoodMapper;
    @Autowired
    SupplierOutsideOrderCarRentalMapper supplierOutsideOrderCarRentalMapper;
    @Autowired
    SupplierOutsideOrderHotelCheckInMapper supplierOutsideOrderHotelCheckInMapper;
    @Autowired
    SupplierOutsideOrderOtherMapper supplierOutsideOrderOtherMapper;
    @Autowired
    SupplierOutsideOrderAdmissionTicketMapper supplierOutsideOrderAdmissionTicketMapper;
    @Autowired
    SupplierSystemOrderHotelCheckInMapper supplierSystemOrderHotelCheckInMapper;
    @Autowired
    SupplierSystemOrderAirMapper supplierSystemOrderAirMapper;
    @Autowired
    SupplierSystemOrderTrainMapper supplierSystemOrderTrainMapper;
    @Autowired
    SupplierSystemOrderBusMapper supplierSystemOrderBusMapper;
    @Autowired
    SupplierSystemOrderShipMapper supplierSystemOrderShipMapper;
    @Autowired
    SupplierSystemOrderAdmissionTicketMapper supplierSystemOrderAdmissionTicketMapper;
    @Autowired
    SupplierSystemOrderInsuranceMapper supplierSystemOrderInsuranceMapper;
    @Autowired
    SupplierSystemOrderStampDutyMapper supplierSystemOrderStampDutyMapper;
    @Autowired
    SupplierSystemOrderAirExpressInfoMapper supplierSystemOrderAirExpressInfoMapper;
    @Autowired
    SupplierSystemOrderVisaMapper supplierSystemOrderVisaMapper;
    @Autowired
    SupplierSystemOrderLocalFunMapper supplierSystemOrderLocalFunMapper;
    @Autowired
    SupplierSystemOrderCommodityMapper supplierSystemOrderCommodityMapper;
    @DubboReference
    ISupplierOutsideOrderAirService supplierOutsideOrderAirService;
    @DubboReference
    ISupplierOutsideOrderTrainService supplierOutsideOrderTrainService;
    @DubboReference
    ISupplierOutsideOrderShipService supplierOutsideOrderShipService;
    @DubboReference
    ISupplierOutsideOrderFoodService supplierOutsideOrderFoodService;
    @DubboReference
    ISupplierOutsideOrderCarRentalService supplierOutsideOrderCarRentalService;
    @DubboReference
    ISupplierOutsideOrderHotelCheckInService supplierOutsideOrderHotelCheckInService;
    @DubboReference
    ISupplierOutsideOrderOtherService supplierOutsideOrderOtherService;
    @DubboReference
    ISupplierOutsideOrderAdmissionTicketService supplierOutsideOrderAdmissionTicketService;
    @DubboReference
    ISupplierSystemOrderHotelCheckInService supplierSystemOrderHotelCheckInService;
    @DubboReference
    ISupplierSystemOrderAirService supplierSystemOrderAirService;
    @DubboReference
    ISupplierSystemOrderTrainService supplierSystemOrderTrainService;
    @DubboReference
    ISupplierSystemOrderBusService supplierSystemOrderBusService;
    @DubboReference
    ISupplierSystemOrderShipService supplierSystemOrderShipService;
    @DubboReference
    ISupplierSystemOrderAdmissionTicketService supplierSystemOrderAdmissionTicketService;
    @DubboReference
    ISupplierSystemOrderInsuranceService supplierSystemOrderInsuranceService;
    @DubboReference
    ISupplierSystemOrderStampDutyService supplierSystemOrderStampDutyService;
    @DubboReference
    ISupplierSystemOrderAirExpressInfoService supplierSystemOrderAirExpressInfoService;
    @DubboReference
    ISupplierSystemOrderVisaService supplierSystemOrderVisaService;
    @DubboReference
    ISupplierSystemOrderLocalFunService supplierSystemOrderLocalFunService;
    @DubboReference
    ISupplierSystemOrderCommodityService supplierSystemOrderCommodityService;
    @DubboReference
    ISysUserService sysUserService;
    @DubboReference
    ISysApprovalService sysApprovalService;
    @DubboReference
    ISysDepartmentService sysDepartmentService;
    @DubboReference
    IMainDataCurrencyService mainDataCurrencyService;
    @DubboReference
    ISysSupplierCostItemService sysSupplierCostItemService;
    @DubboReference
    IHotelOrderService hotelOrderService;
    @DubboReference
    IAirOrderService airOrderService;
    @DubboReference
    ITrainOrderService trainOrderService;
    @DubboReference
    IBusOrderService busOrderService;
    @DubboReference
    IShipOrderService shipOrderService;
    @DubboReference
    IScenicOrderService scenicOrderService;
    @DubboReference
    IVisaOrderService visaOrderService;
    @DubboReference
    ILocalFunOrderService localFunOrderService;
    @DubboReference
    private IHotelOrderCenterService hotelOrderCenterService;
    @DubboReference
    private IFinanceSupplierReconciliationService financeSupplierReconciliationService;

    /**
     * 預訂單號,編號規則：YDD+年後2位+月日4位+時分秒6位+4位随机数字
     *
     * @param nowLocalDateTime
     * @return
     */
    private String generatorOrderNumber(LocalDateTime nowLocalDateTime) {
        String yearCode = String.valueOf(nowLocalDateTime.getYear()).substring(2, 4);
        String monthCode = StringUtils.leftPad(String.valueOf(nowLocalDateTime.getMonthValue()), 2, "0");
        String dayCode = StringUtils.leftPad(String.valueOf(nowLocalDateTime.getDayOfMonth()), 2, "0");
        String randomNumber = String.valueOf((int) ((Math.random() * 9 + 1) * 1000));
        StringBuilder orderNumberSb = new StringBuilder();
        orderNumberSb.append("YDD").append(yearCode).append(monthCode).append(dayCode).append(randomNumber);
        return orderNumberSb.toString().toUpperCase();
    }

    /**
     * 保存供应商预订数据
     *
     * @param userId
     * @param nowDateTime
     * @param supplierOrder
     */
    private void saveOutsideBookingOrder(Long userId, LocalDateTime nowDateTime, SupplierOrder supplierOrder, Integer submitType, Integer sysApprovalType) {
        // 获取汇率, 计算本位币
        BigDecimal plannedExchangeRate = getPlanExchangeRateById(supplierOrder.getCurrencyId());
        BigDecimal standardAmount = supplierOrder.getPayableAmount().multiply(plannedExchangeRate);
        standardAmount = standardAmount.setScale(2, BigDecimal.ROUND_UP).stripTrailingZeros();
        supplierOrder.setStandardAmount(standardAmount);
        //
        supplierOrder.setModifiedId(userId);
        supplierOrder.setGmtModified(nowDateTime);
        if (Objects.equals(submitType, SUBMIT_TYPE_SAVE)) {
            supplierOrder.setCheckStatus(ApprovalStatus.WAIT_SUBMIT.getCode());
        } else if (Objects.equals(submitType, SUBMIT_TYPE_CHECK)) {
            supplierOrder.setCheckStatus(ApprovalStatus.REVIEWING.getCode());
        }
        if (supplierOrder.getId() == null) { // 新增
            supplierOrder.setPayStatus(OrderPaymentStatus.UN_PAYMENT.getCode());
            supplierOrder.setVerifyStatus(SupplierVerifyStatusEnum.UNREADY_VERIFY.getCode());
            supplierOrder.setId(SnowflakeIdWorker.nextId());
            supplierOrder.setCreateId(userId);
            supplierOrder.setGmtCreate(nowDateTime);
            supplierOrder.setIsDeleted(IsDeletedCode.NO.getCode());
            supplierOrder.setOrderNumber(generatorOrderNumber(nowDateTime));
            supplierOrderMapper.insert(supplierOrder);
        } else { //更新
            supplierOrderMapper.updateById(supplierOrder);
        }
        // 提交类型为审批，发起审批电子流
        if (Objects.equals(submitType, SUBMIT_TYPE_CHECK)) {
            log.info("【供应商预订-保存团队预订】发起审批流请求, id:{}, userId:{}, businessType:{}, sysApprovalType:{}", supplierOrder.getId(), userId, supplierOrder.getBusinessType(), sysApprovalType);
            Result<ApprovalStartDTO> result = sysApprovalService.start(supplierOrder.getBusinessType(), sysApprovalType, supplierOrder.getId(), userId, supplierOrder.getTotalFee(), null);
            log.info("【供应商预订-保存团队预订】发起审批流响应, id:{}, result:{}", supplierOrder.getId(), JSON.toJSONString(result));
            if (!result.isSuccess()) {
                throw new BusinessException(SystemError.getDefined(result.getCode()));
            }
        }
    }

    private void saveSupplierOrder(Long userId, LocalDateTime nowDateTime, SupplierOrder supplierOrder) {
        // 获取汇率, 计算本位币
        BigDecimal plannedExchangeRate = getPlanExchangeRateById(supplierOrder.getCurrencyId());
        BigDecimal standardAmount = supplierOrder.getPayableAmount().multiply(plannedExchangeRate);
        standardAmount = standardAmount.setScale(2, BigDecimal.ROUND_UP).stripTrailingZeros();
        supplierOrder.setStandardAmount(standardAmount);

        supplierOrder.setModifiedId(userId);
        supplierOrder.setGmtModified(nowDateTime);
        if (supplierOrder.getId() == null) {
            supplierOrder.setId(SnowflakeIdWorker.nextId());
            supplierOrder.setCreateId(userId);
            supplierOrder.setGmtCreate(nowDateTime);
            supplierOrder.setIsDeleted(IsDeletedCode.NO.getCode());
            supplierOrder.setOrderNumber(generatorOrderNumber(nowDateTime));
            supplierOrderMapper.insert(supplierOrder);
        } else {
            supplierOrderMapper.updateById(supplierOrder);
        }
    }

    @Override
    public PageResponse<SupplierOrderFinishPageDTO> getFinanceContactsPage(SupplierOrderFinancePageReq supplierOrderFinancePageReq) {
        //查询列表
        Page<SupplierOrder> airportExpressPage = new Page<>(supplierOrderFinancePageReq.getPageNo(), supplierOrderFinancePageReq.getPageSize());
        QueryWrapper<SupplierOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SupplierOrder::getIsDeleted, IsDeletedCode.NO);
        queryWrapper.lambda().eq(SupplierOrder::getCheckStatus, CheckStatusCode.APPROVAL_PASS.getCode()).or()
                .eq(SupplierOrder::getReserveStatus, OrderScheduledStatus.RESERVE_SUCCESS.getCode());
        queryWrapper.lambda().eq(supplierOrderFinancePageReq.getSupplierId() != null, SupplierOrder::getOrderNumber, supplierOrderFinancePageReq.getSupplierId());
        queryWrapper.lambda().eq(supplierOrderFinancePageReq.getReserveTypeId() != null, SupplierOrder::getReserveTypeId, supplierOrderFinancePageReq.getReserveTypeId());
        queryWrapper.lambda().eq(supplierOrderFinancePageReq.getCheckStatus() != null, SupplierOrder::getCheckStatus, supplierOrderFinancePageReq.getCheckStatus());
        queryWrapper.lambda().eq(supplierOrderFinancePageReq.getCurrencyId() != null, SupplierOrder::getCurrencyId, supplierOrderFinancePageReq.getCurrencyId());
        queryWrapper.lambda().eq(StringUtils.isNotBlank(supplierOrderFinancePageReq.getOrderNumber()), SupplierOrder::getOrderNumber, supplierOrderFinancePageReq.getOrderNumber());
        queryWrapper.lambda().eq(StringUtils.isNotBlank(supplierOrderFinancePageReq.getProductNumber()), SupplierOrder::getProductNumber, supplierOrderFinancePageReq.getProductNumber());
        queryWrapper.lambda().eq(supplierOrderFinancePageReq.getPayTypeId() != null, SupplierOrder::getPayTypeId, supplierOrderFinancePageReq.getPayTypeId());
        queryWrapper.lambda().ge(supplierOrderFinancePageReq.getFromGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderFinancePageReq.getFromGmtCreate());
        queryWrapper.lambda().le(supplierOrderFinancePageReq.getToGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderFinancePageReq.getToGmtCreate());

        queryWrapper.lambda().orderByDesc(SupplierOrder::getGmtCreate);
        Page<SupplierOrder> iPage = supplierOrderMapper.selectPage(airportExpressPage, queryWrapper);
        List<SupplierOrder> records = iPage.getRecords();
        if (CollectionUtils.isEmpty(records)) {
            return new PageResponse<>(new ArrayList<>(), iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
        }
        List<SupplierOrderFinishPageDTO> supplierOrderFinishPageDTOList = EntityUtil.copyList(records, SupplierOrderFinishPageDTO.class);
        supplierOrderFinishPageDTOList.forEach(supplier -> {
            UserDTO userDTO = sysUserService.queryCacheUser(supplier.getCreateId());
            if (userDTO != null) {
                supplier.setCreate(userDTO.getCreateDept());
            }
        });
        return new PageResponse<>(supplierOrderFinishPageDTOList, iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
    }

    @Override
    public PageResponse<SupplierOrderFinishPageDTO> getFinishPage(SupplierOrderFinishPageReq supplierOrderFinishPageReq) {
        //查询列表
        Page<SupplierOrder> airportExpressPage = new Page<>(supplierOrderFinishPageReq.getPageNo(), supplierOrderFinishPageReq.getPageSize());
        QueryWrapper<SupplierOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SupplierOrder::getIsDeleted, IsDeletedCode.NO);
        queryWrapper.lambda().eq(SupplierOrder::getCheckStatus, CheckStatusCode.APPROVAL_PASS.getCode()).or()
                .eq(SupplierOrder::getReserveStatus, OrderScheduledStatus.RESERVE_SUCCESS.getCode());
        queryWrapper.lambda().eq(supplierOrderFinishPageReq.getSupplierId() != null, SupplierOrder::getOrderNumber, supplierOrderFinishPageReq.getSupplierId());
        queryWrapper.lambda().eq(supplierOrderFinishPageReq.getReserveTypeId() != null, SupplierOrder::getReserveTypeId, supplierOrderFinishPageReq.getReserveTypeId());
        queryWrapper.lambda().eq(StringUtils.isNotBlank(supplierOrderFinishPageReq.getOrderNumber()), SupplierOrder::getOrderNumber, supplierOrderFinishPageReq.getOrderNumber());
        queryWrapper.lambda().eq(StringUtils.isNotBlank(supplierOrderFinishPageReq.getProductNumber()), SupplierOrder::getProductNumber, supplierOrderFinishPageReq.getProductNumber());
        queryWrapper.lambda().eq(supplierOrderFinishPageReq.getScheduleId() != null, SupplierOrder::getScheduleId, supplierOrderFinishPageReq.getScheduleId());
        queryWrapper.lambda().ge(supplierOrderFinishPageReq.getFromGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderFinishPageReq.getFromGmtCreate());
        queryWrapper.lambda().le(supplierOrderFinishPageReq.getToGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderFinishPageReq.getToGmtCreate());

        queryWrapper.lambda().orderByDesc(SupplierOrder::getGmtCreate);
        Page<SupplierOrder> iPage = supplierOrderMapper.selectPage(airportExpressPage, queryWrapper);
        List<SupplierOrder> records = iPage.getRecords();
        if (CollectionUtils.isEmpty(records)) {
            return new PageResponse<>(new ArrayList<>(), iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
        }
        List<SupplierOrderFinishPageDTO> supplierOrderFinishPageDTOList = EntityUtil.copyList(records, SupplierOrderFinishPageDTO.class);
        supplierOrderFinishPageDTOList.forEach(supplier -> {
            UserDTO userDTO = sysUserService.queryCacheUser(supplier.getCreateId());
            if (userDTO != null) {
                supplier.setCreate(userDTO.getCreateDept());
            }
        });

        return new PageResponse<>(supplierOrderFinishPageDTOList, iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
    }

    @Override
    public PageResponse<SupplierOrderUnsubBookingPageDTO> getUnsubBookingPage(SupplierOrderUnsubBookingPageReq supplierOrderUnsubBookingPageReq) {
        //查询列表
        Page<SupplierOrder> airportExpressPage = new Page<>(supplierOrderUnsubBookingPageReq.getPageNo(), supplierOrderUnsubBookingPageReq.getPageSize());
        Page<SupplierOrder> iPage = supplierOrderMapper.selectPage(airportExpressPage, new QueryWrapper<SupplierOrder>().lambda()
                .eq(supplierOrderUnsubBookingPageReq.getSupplierId() != null, SupplierOrder::getOrderNumber, supplierOrderUnsubBookingPageReq.getSupplierId())
                .eq(supplierOrderUnsubBookingPageReq.getReserveTypeId() != null, SupplierOrder::getReserveTypeId, supplierOrderUnsubBookingPageReq.getReserveTypeId())
                .eq(StringUtils.isNotBlank(supplierOrderUnsubBookingPageReq.getOrderNumber()), SupplierOrder::getOrderNumber, supplierOrderUnsubBookingPageReq.getOrderNumber())
                .eq(StringUtils.isNotBlank(supplierOrderUnsubBookingPageReq.getProductNumber()), SupplierOrder::getProductNumber, supplierOrderUnsubBookingPageReq.getProductNumber())
                .eq(supplierOrderUnsubBookingPageReq.getScheduleId() != null, SupplierOrder::getScheduleId, supplierOrderUnsubBookingPageReq.getScheduleId())
                .ge(supplierOrderUnsubBookingPageReq.getFromGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderUnsubBookingPageReq.getFromGmtCreate())
                .le(supplierOrderUnsubBookingPageReq.getToGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderUnsubBookingPageReq.getToGmtCreate())
                .eq(SupplierOrder::getIsDeleted, IsDeletedCode.NO)
                .orderByDesc(SupplierOrder::getGmtCreate)
                .select(SupplierOrder::getId, SupplierOrder::getOrderNumber, SupplierOrder::getSupplierId, SupplierOrder::getSupplierName,
                        SupplierOrder::getPayStatus, SupplierOrder::getSupplierOrderNumber, SupplierOrder::getProductType,
                        SupplierOrder::getCurrencyId, SupplierOrder::getCurrency, SupplierOrder::getPayableAmount, SupplierOrder::getProductName,
                        SupplierOrder::getResourceProductName, SupplierOrder::getCreateId, SupplierOrder::getGmtCreate));

        List<SupplierOrder> records = iPage.getRecords();
        if (CollectionUtils.isEmpty(records)) {
            return new PageResponse<>(new ArrayList<>(), iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
        }
        List<SupplierOrderUnsubBookingPageDTO> supplierOrderFinishPageDTOList = EntityUtil.copyList(records, SupplierOrderUnsubBookingPageDTO.class);
        List<Long> ids = supplierOrderFinishPageDTOList.stream().map(SupplierOrderUnsubBookingPageDTO::getId).collect(Collectors.toList());
        Set<Long> userIds = supplierOrderFinishPageDTOList.stream().map(SupplierOrderUnsubBookingPageDTO::getCreateId).collect(Collectors.toSet());
        Result<List<SupplierReconciliationAmountDTO>> byOrderIdList = null;
        List<UserDTO> userDTOS = null;
        try {
            userDTOS = sysUserService.queryCacheUsers(userIds);
            byOrderIdList = financeSupplierReconciliationService.getByOrderIdList(ids);
            if (!byOrderIdList.isSuccess()) {
                log.error("【供应商预订-分页查询退订的预订列表】查询财务对账列表失败,error:{}", byOrderIdList);
            }
        } catch (Exception e) {
            log.error("【供应商预订-分页查询退订的预订列表】异常,error:{}", e.getMessage(), e);
        }
        for (SupplierOrderUnsubBookingPageDTO supplier : supplierOrderFinishPageDTOList) {
            if (CollectionUtils.isNotEmpty(userDTOS)) {
                for (UserDTO userDTO : userDTOS) {
                    if (userDTO.getId().equals(supplier.getCreateId())) {
                        supplier.setCreate(userDTO.getCreateDept());
                        break;
                    }
                }
            }
            boolean alreadySettle = false; // 财务是否已对账
            if (null != byOrderIdList && CollectionUtils.isNotEmpty(byOrderIdList.getData())) {
                for (SupplierReconciliationAmountDTO reconciliation : byOrderIdList.getData()) {
                    if (Objects.equals(reconciliation.getOrderId(), supplier.getId())) {
                        supplier.setPayStatus(reconciliation.getPayStatus());
                        supplier.setPayableAmount(reconciliation.getPayableAmount());
                        supplier.setPaidAmount(reconciliation.getPaidAmount());
                        supplier.setUnPayAmount(reconciliation.getUnPayAmount());
                        alreadySettle = true;
                        break;
                    }
                }
            }
            if (!alreadySettle) {
                supplier.setUnPayAmount(supplier.getPayableAmount());
            }
        }
        return new PageResponse<>(supplierOrderFinishPageDTOList, iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
    }

    @Override
    public PageResponse<SupplierOrderPageDTO> selectPage(SupplierOrderPageReq supplierOrderPageReq) {
        //查询列表
        Page<SupplierOrder> airportExpressPage = new Page<>(supplierOrderPageReq.getPageNo(), supplierOrderPageReq.getPageSize());
        QueryWrapper<SupplierOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SupplierOrder::getIsDeleted, IsDeletedCode.NO);
        queryWrapper.lambda().eq(SupplierOrder::getCheckStatus, CheckStatusCode.APPROVAL_PASS.getCode()).or()
                .eq(SupplierOrder::getReserveStatus, OrderScheduledStatus.RESERVE_SUCCESS.getCode());
        if (supplierOrderPageReq.getDeptId() != null && supplierOrderPageReq.getOrgType() != null) {
            if (supplierOrderPageReq.getOrgType().equals(1)) {
                queryWrapper.lambda().eq(SupplierOrder::getCreateId, supplierOrderPageReq.getDeptId());
            } else {
                List<Long> userIds = sysDepartmentService.queryUserIdsByDeptId(supplierOrderPageReq.getDeptId());
                queryWrapper.lambda().in(SupplierOrder::getCreateId, userIds);
            }
        }
        queryWrapper.lambda().eq(supplierOrderPageReq.getReserveTypeId() != null, SupplierOrder::getReserveTypeId, supplierOrderPageReq.getReserveTypeId());
        queryWrapper.lambda().eq(StringUtils.isNotBlank(supplierOrderPageReq.getOrderNumber()), SupplierOrder::getOrderNumber, supplierOrderPageReq.getOrderNumber());
        queryWrapper.lambda().eq(supplierOrderPageReq.getCurrencyId() != null, SupplierOrder::getCurrencyId, supplierOrderPageReq.getCurrencyId());
        if (StringUtils.isNotBlank(supplierOrderPageReq.getNumber())) {
            queryWrapper.lambda().eq(SupplierOrder::getScheduleId, supplierOrderPageReq.getNumber())
                    .or().eq(SupplierOrder::getProductNumber, supplierOrderPageReq.getNumber());
        }
        queryWrapper.lambda().eq(SupplierOrder::getPayTypeId, supplierOrderPageReq.getPayTypeId());
        queryWrapper.lambda().ge(supplierOrderPageReq.getFromGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderPageReq.getFromGmtCreate());
        queryWrapper.lambda().le(supplierOrderPageReq.getToGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderPageReq.getToGmtCreate());
        queryWrapper.lambda().orderByDesc(SupplierOrder::getGmtCreate);
        Page<SupplierOrder> iPage = supplierOrderMapper.selectPage(airportExpressPage, queryWrapper);
        List<SupplierOrder> records = iPage.getRecords();
        if (CollectionUtils.isEmpty(records)) {
            return new PageResponse<>(new ArrayList<>(), iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
        }
        List<SupplierOrderPageDTO> supplierOrderPageDTOList = EntityUtil.copyList(records, SupplierOrderPageDTO.class);
        return new PageResponse<>(supplierOrderPageDTOList, iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
    }

    @Override
    public Result<List<SupplierOrderDTO>> selectListByIds(List<Long> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return Result.success(new ArrayList<>());
        }
        QueryWrapper<SupplierOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().in(SupplierOrder::getId, ids);
        queryWrapper.lambda().orderByDesc(SupplierOrder::getGmtCreate);
        List<SupplierOrder> supplierOrders = supplierOrderMapper.selectList(queryWrapper);
        List<SupplierOrderDTO> supplierOrderDTOList = EntityUtil.copyList(supplierOrders, SupplierOrderDTO.class);
        for (SupplierOrderDTO supplierOrderDTO : supplierOrderDTOList) {
            UserDTO userDTO = sysUserService.queryCacheUser(supplierOrderDTO.getCreateId());
            supplierOrderDTO.setCreateUser(userDTO.getCreateDept());
        }
        return Result.success(supplierOrderDTOList);
    }

    /**
     * 根据id查询供应商预订单
     *
     * @param id
     * @return
     */
    @Override
    public Result<SupplierOrderDTO> selectListById(Long id) {
        SupplierOrderDTO dto = null;
        SupplierOrder order = supplierOrderMapper.selectById(id);
        if (order != null && Objects.equals(order.getIsDeleted(), IsDeletedCode.NO.getCode())) {
            dto = EntityUtil.copy(order, SupplierOrderDTO.class);
            UserDTO userDTO = sysUserService.queryCacheUser(dto.getCreateId());
            dto.setCreateUser(userDTO.getCreateDept());
        }
        return Result.success(dto);
    }

    @Override
    public Result submitOutsideApproval(long id, Long userId) {
        log.info("【供应商预订-提交审批】方法入参, id:{}, userId:{}", id, userId);
        try {
            SupplierOrder supplierOrder = supplierOrderMapper.selectOne(new QueryWrapper<SupplierOrder>().lambda()
                    .eq(SupplierOrder::getId, id)
                    .eq(SupplierOrder::getIsDeleted, IsDeletedCode.NO.getCode()));
            if (Objects.equals(supplierOrder.getCheckStatus(), ApprovalStatus.WAIT_SUBMIT)) {
                throw new BusinessException(SystemError.SUPPLIER_BOOKING_13703);
            }
            SupplierReserveTypeEnum supplierReserveType = SupplierReserveTypeEnum.parseById(supplierOrder.getReserveTypeId());
            Integer code = 0;
            switch (supplierReserveType) {
                case AIR:
                    code = 25;
                    break;
                case TRAIN:
                    code = 26;
                    break;
                case SHIP:
                    code = 27;
                    break;
                case CAR_RENTAL:
                    code = 28;
                    break;
                case FOOD:
                    code = 29;
                    break;
                case HOTEL:
                    code = 30;
                    break;
                case OTHER:
                    code = 31;
                    break;
                case SCENIC:
                    code = 32;
                    break;
            }
            StringBuffer sb = new StringBuffer();
            sb.append(StringUtils.leftPad(String.valueOf(supplierOrder.getBusinessType()), 2, "0"));
            sb.append(code);
            Integer sysApprovalType = Integer.valueOf(sb.toString());
            log.info("【供应商预订-提交审批】更新订单, id:{}", id);
            supplierOrderMapper.update(null, new UpdateWrapper<SupplierOrder>().lambda()
                    .eq(SupplierOrder::getId, id)
                    .set(SupplierOrder::getCheckStatus, ApprovalStatus.REVIEWING.getCode())
                    .set(SupplierOrder::getModifiedId, userId)
                    .set(SupplierOrder::getGmtModified, LocalDateTime.now()));
            log.info("【供应商预订-提交审批】发起审批流请求, id:{}, userId:{}, businessType:{}, sysApprovalType:{}", supplierOrder.getId(), userId, supplierOrder.getBusinessType(), sysApprovalType);
            Result<ApprovalStartDTO> result = sysApprovalService.start(supplierOrder.getBusinessType(), sysApprovalType, supplierOrder.getId(), userId, supplierOrder.getTotalFee(), null);
            log.info("【供应商预订-提交审批】发起审批流响应, id:{}, result:{}", supplierOrder.getId(), JSON.toJSONString(result));
            if (!result.isSuccess()) {
                throw new BusinessException(SystemError.getDefined(result.getCode()));
            }
        } catch (BusinessException e) {
            log.error("【供应商预订-提交审批】调用保险预订失败,error:{}", e.getMessage(), e);
            throw new BusinessException(SystemError.getDefined(e.getCode()));
        } catch (Exception e) {
            log.error("【供应商预订-提交审批】系统异常,error:{}", e.getMessage(), e);
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_13702);
        }
        return Result.success();
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result approvalOutside(SupplierOrderOutsideApprovalReq req) {
        log.info("【供应商预订-团队预订审批】方法入参, approvalReq:{}", JSON.toJSONString(req));
        if (req.getApprovalId() == null) {
            return Result.failed(SystemError.SYS_402);
        }
        if (!ApprovalStatus.isCheckStatus(req.getApprovalStatus())) {
            return Result.failed(SystemError.SYS_402);
        }

        QueryWrapper<SupplierOrder> orderQueryWrapper = new QueryWrapper<>();
        orderQueryWrapper.lambda().eq(SupplierOrder::getId, req.getBusinessId());
        orderQueryWrapper.lambda().eq(SupplierOrder::getIsDeleted, IsDeletedCode.NO);
        SupplierOrder supplierOrder = supplierOrderMapper.selectOne(orderQueryWrapper);
        if (supplierOrder == null) {
            return Result.failed(SystemError.AIREXPRESS_ORDER_60002);
        }
        if (!CheckStatusCode.APPROVAL.getCode().equals(supplierOrder.getCheckStatus())) {
            return Result.failed(SystemError.AIREXPRESS_ORDER_60027);
        }
        /**
         * 审批
         */
        log.info("【供应商预订-团队预订审批】工作流审批请求, approvalReq:{}", JSON.toJSONString(req));
        Result<ApprovalCheckDTO> result = sysApprovalService.check(req.getApprovalId(), req.getUserId(),
                req.getApprovalStatus(), req.getComments());
        log.info("【供应商预订-团队预订审批】工作流审批响应, result:{}", JSON.toJSONString(result));
        if (!result.isSuccess()) {
            SystemError systemError = SystemError.getDefined(result.getCode());
            return Result.failed(systemError);
        }
        if (result.getData() == null || !result.getData().getIsFinish()) {
            return Result.success();
        }
        LocalDateTime nowLocalDateTime = LocalDateTime.now();
        log.info("【供应商预订-团队预订】approval status:{}", req.getApprovalStatus());
        if (ApprovalStatus.REVIEW_YES.getCode() == req.getApprovalStatus()) {
            //审批通过
            supplierOrder.setCheckStatus(CheckStatusCode.APPROVAL_PASS.getCode());
        } else if (ApprovalStatus.REVIEW_NO.getCode() == req.getApprovalStatus()) {
            //审批不通过
            supplierOrder.setCheckStatus(CheckStatusCode.APPROVAL_NOT_PASS.getCode());
        } else {
            //撤回
            supplierOrder.setCheckStatus(CheckStatusCode.WAIT_SUBMIT.getCode());
        }
        supplierOrder.setModifiedId(req.getUserId());
        supplierOrder.setGmtModified(nowLocalDateTime);
        supplierOrderMapper.updateById(supplierOrder);
        return Result.success();
    }

    @Override
    public PageResponse<SupplierOrderOutsidePageDTO> selectOutsideList(SupplierOrderOutsidePageReq supplierOrderOutsidePageReq) {
        Page<SupplierOrder> supplierOutsideOrderPage = new Page<>(supplierOrderOutsidePageReq.getPageNo(), supplierOrderOutsidePageReq.getPageSize());
        Page<SupplierOrder> iPage = supplierOrderMapper.selectPage(supplierOutsideOrderPage, new QueryWrapper<SupplierOrder>().lambda()
                .like(StringUtils.isNotBlank(supplierOrderOutsidePageReq.getOrderNumber()), SupplierOrder::getOrderNumber, supplierOrderOutsidePageReq.getOrderNumber())
                .eq(supplierOrderOutsidePageReq.getBusinessType() != null, SupplierOrder::getBusinessType, supplierOrderOutsidePageReq.getBusinessType())
                .ge(supplierOrderOutsidePageReq.getFromGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderOutsidePageReq.getFromGmtCreate())
                .le(supplierOrderOutsidePageReq.getToGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderOutsidePageReq.getToGmtCreate())
                .ge(supplierOrderOutsidePageReq.getFromExpectedPayTime() != null, SupplierOrder::getExpectedPayTime, supplierOrderOutsidePageReq.getFromExpectedPayTime())
                .le(supplierOrderOutsidePageReq.getToExpectedPayTime() != null, SupplierOrder::getExpectedPayTime, supplierOrderOutsidePageReq.getToExpectedPayTime())
                .eq(supplierOrderOutsidePageReq.getSupplierId() != null, SupplierOrder::getSupplierId, supplierOrderOutsidePageReq.getSupplierId())
                .like(StringUtils.isNotBlank(supplierOrderOutsidePageReq.getScheduleId()), SupplierOrder::getScheduleId, supplierOrderOutsidePageReq.getScheduleId())
                .like(StringUtils.isNotBlank(supplierOrderOutsidePageReq.getResourceProductName()), SupplierOrder::getResourceProductName, supplierOrderOutsidePageReq.getResourceProductName())
                .eq(supplierOrderOutsidePageReq.getCreateId() != null, SupplierOrder::getCreateId, supplierOrderOutsidePageReq.getCreateId())
                .eq(supplierOrderOutsidePageReq.getVerifyStatus() != null, SupplierOrder::getVerifyStatus, supplierOrderOutsidePageReq.getVerifyStatus())
                .eq(supplierOrderOutsidePageReq.getReserveTypeId() != null, SupplierOrder::getReserveTypeId, supplierOrderOutsidePageReq.getReserveTypeId())
                .eq(supplierOrderOutsidePageReq.getCheckStatus() != null, SupplierOrder::getCheckStatus, supplierOrderOutsidePageReq.getCheckStatus())

                .in(SupplierOrder::getBusinessType, SystemBusinessType.getGroupList()) //只查询团队预订数据
                .orderByDesc(SupplierOrder::getGmtCreate));
        List<SupplierOrder> records = iPage.getRecords();
        if (CollectionUtils.isEmpty(records)) {
            return new PageResponse<>(new ArrayList<>(), iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
        }
        List<SupplierOrderOutsidePageDTO> supplierOrderOutsidePageDTOList = EntityUtil.copyList(records, SupplierOrderOutsidePageDTO.class);
        for (SupplierOrderOutsidePageDTO supplierOrderOutsidePageDTO : supplierOrderOutsidePageDTOList) {
            UserDTO userDTO = sysUserService.queryCacheUser(supplierOrderOutsidePageDTO.getCreateId());
            supplierOrderOutsidePageDTO.setCreateUser(userDTO.getCreateDept());
        }
        return new PageResponse<>(supplierOrderOutsidePageDTOList, iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result saveOutsideAir(SupplierOrderOutsideAirSaveReq supplierOrderOutsideAirSaveReq, Long userId) {
        LocalDateTime nowDateTime = LocalDateTime.now();
        SupplierOrder supplierOrder = EntityUtil.copy(supplierOrderOutsideAirSaveReq, SupplierOrder.class);

        if (supplierOrderOutsideAirSaveReq.getSubmitType() == SUBMIT_TYPE_INNER) {
            //供应商预订-付款方式为'内部挂账'逻辑
            buildSupplierBookingOrder(supplierOrder, SupplierReserveTypeEnum.AIR);
            /**
             * 构建内部挂账供应商预订单
             */
            saveInnerSupplierOrder(supplierOrder, userId, nowDateTime);
        }
        saveOutsideBookingOrder(userId, nowDateTime, supplierOrder, supplierOrderOutsideAirSaveReq.getSubmitType(), supplierOrderOutsideAirSaveReq.getSysApprovalType());

        //保存机票子表
        supplierOutsideOrderAirService.save(supplierOrder.getId(), userId, nowDateTime, supplierOrderOutsideAirSaveReq.getSupplierOutsideOrderAirList());
        return Result.success(supplierOrder.getId());
    }

    @Override
    public SupplierOrderAirDTO selectOutsideAirById(Long id, Long userId) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(id);
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_AIR_13002);
        }
        List<SupplierOutsideOrderAirDTO> supplierOutsideOrderAirDTOS = supplierOutsideOrderAirService.selectByOrderId(id);
        SupplierOrderAirDTO supplierOrderAirDTO = EntityUtil.copy(supplierOrder, SupplierOrderAirDTO.class);
        supplierOrderAirDTO.setSupplierOutsideOrderAirDTOList(supplierOutsideOrderAirDTOS);
        return supplierOrderAirDTO;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result saveOutsideTrain(SupplierOrderOutsideTrainSaveReq supplierOrderOutsideTrainSaveReq, Long userId) {
        LocalDateTime nowDateTime = LocalDateTime.now();
        SupplierOrder supplierOrder = EntityUtil.copy(supplierOrderOutsideTrainSaveReq, SupplierOrder.class);

        if (supplierOrderOutsideTrainSaveReq.getSubmitType() == SUBMIT_TYPE_INNER) {
            //供应商预订-付款方式为'内部挂账'逻辑
            buildSupplierBookingOrder(supplierOrder, SupplierReserveTypeEnum.TRAIN);
            /**
             * 构建内部挂账供应商预订单
             */
            saveInnerSupplierOrder(supplierOrder, userId, nowDateTime);
        }
        saveOutsideBookingOrder(userId, nowDateTime, supplierOrder, supplierOrderOutsideTrainSaveReq.getSubmitType(), supplierOrderOutsideTrainSaveReq.getSysApprovalType());
        //保存火车票票子表
        supplierOutsideOrderTrainService.save(supplierOrder.getId(), userId, nowDateTime, supplierOrderOutsideTrainSaveReq.getSupplierOutsideOrderTrainReqList());
        return Result.success(supplierOrder.getId());
    }

    @Override
    public SupplierOrderTrainDTO selectOutsideTrainById(Long id, Long userId) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(id);
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_TRAIN_13101);
        }
        List<SupplierOutsideOrderTrainDTO> supplierOutsideOrderTrainDTOS = supplierOutsideOrderTrainService.selectByOrderId(id);
        SupplierOrderTrainDTO supplierOrderTrainDTO = EntityUtil.copy(supplierOrder, SupplierOrderTrainDTO.class);
        supplierOrderTrainDTO.setSupplierOutsideOrderTrainDTOList(supplierOutsideOrderTrainDTOS);
        return supplierOrderTrainDTO;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result saveOutsideShip(SupplierOrderOutsideShipSaveReq supplierOrderOutsideShipSaveReq, Long userId) {
        LocalDateTime nowDateTime = LocalDateTime.now();
        SupplierOrder supplierOrder = EntityUtil.copy(supplierOrderOutsideShipSaveReq, SupplierOrder.class);

        if (supplierOrderOutsideShipSaveReq.getSubmitType() == SUBMIT_TYPE_INNER) {
            //供应商预订-付款方式为'内部挂账'逻辑
            buildSupplierBookingOrder(supplierOrder, SupplierReserveTypeEnum.SHIP);
            /**
             * 构建内部挂账供应商预订单
             */
            saveInnerSupplierOrder(supplierOrder, userId, nowDateTime);
        }
        saveOutsideBookingOrder(userId, nowDateTime, supplierOrder, supplierOrderOutsideShipSaveReq.getSubmitType(), supplierOrderOutsideShipSaveReq.getSysApprovalType());
        //保存火车票票子表
        supplierOutsideOrderShipService.save(supplierOrder.getId(), userId, nowDateTime, supplierOrderOutsideShipSaveReq.getSupplierOutsideOrderShipReqList());
        return Result.success(supplierOrder.getId());
    }

    @Override
    public SupplierOrderShipDTO selectOutsideShipById(Long id, Long userId) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(id);
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_SHIP_13201);
        }
        List<SupplierOutsideOrderShipDTO> supplierOutsideOrderShipDTOS = supplierOutsideOrderShipService.selectByOrderId(id);
        SupplierOrderShipDTO supplierOrderShipDTO = EntityUtil.copy(supplierOrder, SupplierOrderShipDTO.class);
        supplierOrderShipDTO.setSupplierOutsideOrderShipDTOList(supplierOutsideOrderShipDTOS);
        return supplierOrderShipDTO;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result saveOutsideFood(SupplierOrderOutsideFoodSaveReq supplierOrderOutsideFoodSaveReq, Long userId) {
        LocalDateTime nowDateTime = LocalDateTime.now();
        SupplierOrder supplierOrder = EntityUtil.copy(supplierOrderOutsideFoodSaveReq, SupplierOrder.class);

        if (supplierOrderOutsideFoodSaveReq.getSubmitType() == SUBMIT_TYPE_INNER) {
            //供应商预订-付款方式为'内部挂账'逻辑
            buildSupplierBookingOrder(supplierOrder, SupplierReserveTypeEnum.FOOD);
            /**
             * 构建内部挂账供应商预订单
             */
            saveInnerSupplierOrder(supplierOrder, userId, nowDateTime);
        }
        saveOutsideBookingOrder(userId, nowDateTime, supplierOrder, supplierOrderOutsideFoodSaveReq.getSubmitType(), supplierOrderOutsideFoodSaveReq.getSysApprovalType());
        //保存餐饮子表
        supplierOutsideOrderFoodService.save(supplierOrder.getId(), userId, nowDateTime, supplierOrderOutsideFoodSaveReq.getSupplierOutsideOrderFoodReqList());
        return Result.success(supplierOrder.getId());
    }

    @Override
    public SupplierOrderFoodDTO selectOutsideFoodById(Long id, Long userId) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(id);
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_FOOD_13301);
        }
        List<SupplierOutsideOrderFoodDTO> supplierOutsideOrderFoodDTOS = supplierOutsideOrderFoodService.selectByOrderId(id);
        SupplierOrderFoodDTO supplierOrderFoodDTO = EntityUtil.copy(supplierOrder, SupplierOrderFoodDTO.class);
        supplierOrderFoodDTO.setSupplierOutsideOrderFoodDTOList(supplierOutsideOrderFoodDTOS);
        return supplierOrderFoodDTO;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result saveOutsideCar(SupplierOrderOutsideCarSaveReq supplierOrderOutsideCarSaveReq, Long userId) {
        LocalDateTime nowDateTime = LocalDateTime.now();
        SupplierOrder supplierOrder = EntityUtil.copy(supplierOrderOutsideCarSaveReq, SupplierOrder.class);

        if (supplierOrderOutsideCarSaveReq.getSubmitType() == SUBMIT_TYPE_INNER) {
            //供应商预订-付款方式为'内部挂账'逻辑
            buildSupplierBookingOrder(supplierOrder, SupplierReserveTypeEnum.CAR_RENTAL);
            /**
             * 构建内部挂账供应商预订单
             */
            saveInnerSupplierOrder(supplierOrder, userId, nowDateTime);
        }
        saveOutsideBookingOrder(userId, nowDateTime, supplierOrder, supplierOrderOutsideCarSaveReq.getSubmitType(), supplierOrderOutsideCarSaveReq.getSysApprovalType());
        //保存餐饮子表
        supplierOutsideOrderCarRentalService.save(supplierOrder.getId(), userId, nowDateTime, supplierOrderOutsideCarSaveReq.getSupplierOutsideOrderCarRentalReqList());
        return Result.success(supplierOrder.getId());
    }

    @Override
    public SupplierOrderCarDTO selectOutsideCarById(Long id, Long userId) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(id);
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_CAR_13401);
        }
        List<SupplierOutsideOrderCarRentalDTO> supplierOutsideOrderCarDTOS = supplierOutsideOrderCarRentalService.selectByOrderId(id);
        SupplierOrderCarDTO supplierOrderCarDTO = EntityUtil.copy(supplierOrder, SupplierOrderCarDTO.class);
        supplierOrderCarDTO.setSupplierOutsideOrderCarRentalDTOList(supplierOutsideOrderCarDTOS);
        return supplierOrderCarDTO;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result saveOutsideOther(SupplierOrderOutsideOtherSaveReq supplierOrderOutsideOtherSaveReq, Long userId) {
        LocalDateTime nowDateTime = LocalDateTime.now();
        SupplierOrder supplierOrder = EntityUtil.copy(supplierOrderOutsideOtherSaveReq, SupplierOrder.class);

        if (supplierOrderOutsideOtherSaveReq.getSubmitType() == SUBMIT_TYPE_INNER) {
            //供应商预订-付款方式为'内部挂账'逻辑
            buildSupplierBookingOrder(supplierOrder, SupplierReserveTypeEnum.OTHER);
            /**
             * 构建内部挂账供应商预订单
             */
            saveInnerSupplierOrder(supplierOrder, userId, nowDateTime);
        }
        saveOutsideBookingOrder(userId, nowDateTime, supplierOrder, supplierOrderOutsideOtherSaveReq.getSubmitType(), supplierOrderOutsideOtherSaveReq.getSysApprovalType());
        //保存综费子表
        supplierOutsideOrderOtherService.save(supplierOrder.getId(), userId, nowDateTime, supplierOrderOutsideOtherSaveReq.getSupplierOutsideOrderOtherReqList());
        return Result.success(supplierOrder.getId());
    }

    @Override
    public SupplierOrderOtherDTO selectOutsideOtherById(Long id, Long userId) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(id);
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_OTHER_13601);
        }
        List<SupplierOutsideOrderOtherDTO> supplierOutsideOrderOtherDTOS = supplierOutsideOrderOtherService.selectByOrderId(id);
        SupplierOrderOtherDTO supplierOrderOtherDTO = EntityUtil.copy(supplierOrder, SupplierOrderOtherDTO.class);
        supplierOrderOtherDTO.setSupplierOutsideOrderOtherDTOList(supplierOutsideOrderOtherDTOS);
        return supplierOrderOtherDTO;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result saveOutsideHotel(SupplierOrderOutsideHotelSaveReq supplierOrderOutsideHotelSaveReq, Long userId) {
        SupplierOrder supplierOrder = EntityUtil.copy(supplierOrderOutsideHotelSaveReq, SupplierOrder.class);
        LocalDateTime nowDateTime = LocalDateTime.now();

        if (supplierOrderOutsideHotelSaveReq.getSubmitType() == SUBMIT_TYPE_INNER) {
            //供应商预订-付款方式为'内部挂账'逻辑
            buildSupplierBookingOrder(supplierOrder, SupplierReserveTypeEnum.HOTEL);
            /**
             * 构建内部挂账供应商预订单
             */
            saveInnerSupplierOrder(supplierOrder, userId, nowDateTime);
        }
        saveOutsideBookingOrder(userId, nowDateTime, supplierOrder, supplierOrderOutsideHotelSaveReq.getSubmitType(), supplierOrderOutsideHotelSaveReq.getSysApprovalType());
        //保存酒店子表
        supplierOutsideOrderHotelCheckInService.save(supplierOrder.getId(), userId, nowDateTime, supplierOrderOutsideHotelSaveReq.getSupplierOutsideOrderHotelCheckInReqList());
        return Result.success(supplierOrder.getId());
    }

    @Override
    public SupplierOrderHotelDTO selectOutsideHotelById(Long id, Long userId) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(id);
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_HOTEL_13501);
        }
        List<SupplierOutsideOrderHotelCheckInDTO> supplierOutsideOrderHotelDTOS = supplierOutsideOrderHotelCheckInService.selectByOrderId(id);
        SupplierOrderHotelDTO supplierOrderHotelDTO = EntityUtil.copy(supplierOrder, SupplierOrderHotelDTO.class);
        supplierOrderHotelDTO.setSupplierOutsideOrderHotelCheckInDTOList(supplierOutsideOrderHotelDTOS);
        return supplierOrderHotelDTO;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result saveOutsideAdmission(SupplierOrderOutsideAdmissionSaveReq supplierOrderOutsideAdmissionSaveReq, Long userId) {
        SupplierOrder supplierOrder = EntityUtil.copy(supplierOrderOutsideAdmissionSaveReq, SupplierOrder.class);
        LocalDateTime nowDateTime = LocalDateTime.now();

        if (supplierOrderOutsideAdmissionSaveReq.getSubmitType() == SUBMIT_TYPE_INNER) {
            //供应商预订-付款方式为'内部挂账'逻辑
            buildSupplierBookingOrder(supplierOrder, SupplierReserveTypeEnum.SCENIC);
            /**
             * 构建内部挂账供应商预订单
             */
            saveInnerSupplierOrder(supplierOrder, userId, nowDateTime);
        }
        saveOutsideBookingOrder(userId, nowDateTime, supplierOrder, supplierOrderOutsideAdmissionSaveReq.getSubmitType(), supplierOrderOutsideAdmissionSaveReq.getSysApprovalType());
        //保存酒店子表
        supplierOutsideOrderAdmissionTicketService.save(supplierOrder.getId(), userId, nowDateTime, supplierOrderOutsideAdmissionSaveReq.getSupplierOutsideOrderAdmissionTicketReqList());
        return Result.success(supplierOrder.getId());
    }

    @Override
    public SupplierOrderAdmissionDTO selectOutsideAdmissionById(Long id, Long userId) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(id);
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_HOTEL_13501);
        }
        List<SupplierOutsideOrderAdmissionTicketDTO> supplierOutsideOrderAdmissionDTOS = supplierOutsideOrderAdmissionTicketService.selectByOrderId(id);
        SupplierOrderAdmissionDTO supplierOrderAdmissionDTO = EntityUtil.copy(supplierOrder, SupplierOrderAdmissionDTO.class);
        supplierOrderAdmissionDTO.setSupplierOutsideOrderAdmissionTicketDTOList(supplierOutsideOrderAdmissionDTOS);
        return supplierOrderAdmissionDTO;
    }


    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result<Long> editSystemHotel(SupplierOrderSystemHotelEditReq supplierOrderSystemHotelEditReq, Long userId) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(supplierOrderSystemHotelEditReq.getId());
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_HOTEL_13501);
        }
        //计算本位币金额
        BigDecimal exchangeRate = getPlanExchangeRateById(supplierOrderSystemHotelEditReq.getCurrencyId());
        List<SupplierSystemOrderHotelCheckIn> supplierSystemOrderHotelCheckIns = supplierSystemOrderHotelCheckInMapper.selectList(new QueryWrapper<SupplierSystemOrderHotelCheckIn>().lambda()
                .in(SupplierSystemOrderHotelCheckIn::getOrderId, supplierOrderSystemHotelEditReq.getId()));
        BigDecimal total = BigDecimal.ZERO;
        for (SupplierSystemOrderHotelCheckInEditReq o : supplierOrderSystemHotelEditReq.getSupplierSystemOrderHotelCheckInEditReqList()) {
            for (SupplierSystemOrderHotelCheckIn hotelCheckIn : supplierSystemOrderHotelCheckIns) {
                if (Objects.equals(hotelCheckIn.getId(), o.getId())) {
                    // 间数乘以晚数
                    BigDecimal numNightNum = new BigDecimal(hotelCheckIn.getNum()).multiply(new BigDecimal(hotelCheckIn.getNightNum()));
                    // 再乘以房价
                    BigDecimal subtotal = numNightNum.multiply(o.getPrice());
                    total = total.add(subtotal);
                    hotelCheckIn.setPrice(o.getPrice());
                    hotelCheckIn.setTotalPrice(subtotal);
                    break;
                }
            }
        }
        BigDecimal standardAmount = total.multiply(exchangeRate);
        supplierOrder = EntityUtil.copy(supplierOrderSystemHotelEditReq, SupplierOrder.class);
        supplierOrder.setPayableAmount(total);
        supplierOrder.setStandardAmount(standardAmount);
        supplierOrder.setModifiedId(userId);
        supplierOrder.setGmtModified(LocalDateTime.now());
        updateSystemOrder(supplierOrder);
        supplierSystemOrderHotelCheckInService.update(supplierOrderSystemHotelEditReq.getSupplierSystemOrderHotelCheckInEditReqList());
        return Result.success(supplierOrderSystemHotelEditReq.getId());
    }

    @Override
    public Result<Long> addSystemHotel(SupplierOrderSystemHotelAddReq supplierOrderSystemHotelAddReq, Long userId) {
        log.info("【供应商预订-新增系统酒店】入参:{},用户ID:{}", JSON.toJSONString(supplierOrderSystemHotelAddReq), userId);
        ValidatorUtil.validate(supplierOrderSystemHotelAddReq);
        SupplierOrder supplierOrder = EntityUtil.copy(supplierOrderSystemHotelAddReq, SupplierOrder.class);
        LocalDateTime nowDateTime = LocalDateTime.now();

        // 构建供应商预订单-供应商数据、汇率本位币
        buildSystemSupplier(supplierOrder, nowDateTime);
        // 构建供应商预订单-状态数据
        buildSupplierBookingOrder(supplierOrder, SupplierReserveTypeEnum.HOTEL);
        /**
         * 构建内部挂账供应商预订单
         */
        saveInnerSupplierOrder(supplierOrder, userId, nowDateTime);
        saveSupplierOrder(userId, nowDateTime, supplierOrder);
        supplierSystemOrderHotelCheckInService.add(supplierOrder.getId(), userId, nowDateTime, supplierOrderSystemHotelAddReq.getSupplierSystemOrderHotelCheckInAddReqList());
        return Result.success(supplierOrder.getId());
    }

    /**
     * 构建供应商信息
     *
     * @param supplierOrder
     * @param nowDateTime
     */
    private void buildSystemSupplier(SupplierOrder supplierOrder, LocalDateTime nowDateTime) {
        /**
         * 构建供应商
         */
        QuerySupplierCostItemReq querySupplierCostItemReq = new QuerySupplierCostItemReq();
        querySupplierCostItemReq.setSupplierId(supplierOrder.getSupplierId());
        Result<List<QuerySupplierCostItemDTO>> sysSupplierDTOResult = sysSupplierCostItemService.querySupplierCostItem(querySupplierCostItemReq);
        if (!sysSupplierDTOResult.isSuccess()) {//获取供应商类型
            log.error("【供应商预订单-自由行预订-支付订单】查询供应商失败,supplier id:{},result:{}", supplierOrder.getSupplierId(), JSON.toJSONString(sysSupplierDTOResult));
            throw new BusinessException(SystemError.AIREXPRESS_ORDER_60033);
        }
        List<QuerySupplierCostItemDTO> supplierList = sysSupplierDTOResult.getData();
        if (CollectionUtils.isEmpty(supplierList)) {//获取供应商类型
            log.error("【供应商预订单-自由行预订-支付订单】查询供应商失败,供应商数据不存在,supplier id:{},error:{}", supplierOrder.getSupplierId(), JSON.toJSONString(sysSupplierDTOResult));
            throw new BusinessException(SystemError.AIREXPRESS_ORDER_60033);
        }
        log.info("【供应商预订单-自由行预订-支付订单】查询供应商, data:{}", JSON.toJSONString(sysSupplierDTOResult));
        QuerySupplierCostItemDTO querySupplierCostItemDTO = supplierList.get(0);
        supplierOrder.setSupplierName(querySupplierCostItemDTO.getCnName()); //供应商名称
        supplierOrder.setSupplierType(querySupplierCostItemDTO.getPlatformSysType()); // 供应商类型
        supplierOrder.setSupplierContactName(querySupplierCostItemDTO.getContactName());
        supplierOrder.setSupplierContactMobileAreaCode(querySupplierCostItemDTO.getContactAreaCode());
        supplierOrder.setSupplierContactMobile(querySupplierCostItemDTO.getContactMobile());
        supplierOrder.setSupplierContactEmail(querySupplierCostItemDTO.getBusinessEmail());
        supplierOrder.setSupplierContactFax(querySupplierCostItemDTO.getContactFax());
        if (querySupplierCostItemDTO.getPayMethod() != null) {
            supplierOrder.setPayTypeId(Long.valueOf(querySupplierCostItemDTO.getPayMethod())); // 付款类型
            supplierOrder.setPayType(SupplierPaymentType.getEnumName(querySupplierCostItemDTO.getPayMethod()));
        }
        // 构建供应商期望付款时间
        LocalDateTime expectedPayTime;
        if (Objects.equals(querySupplierCostItemDTO.getSettlementPeriodType(), 1)) {
            //按天
            expectedPayTime = nowDateTime.plusDays(querySupplierCostItemDTO.getSettlementPeriod());
        } else if (Objects.equals(querySupplierCostItemDTO.getSettlementPeriodType(), 2)) {
            //按周
            expectedPayTime = nowDateTime.plusWeeks(querySupplierCostItemDTO.getSettlementPeriod());
        } else {
            //按月
            expectedPayTime = nowDateTime.plusHours(querySupplierCostItemDTO.getSettlementPeriod());
        }
        supplierOrder.setExpectedPayTime(expectedPayTime);
        /**
         * 汇率本位币
         */
        BigDecimal plannedExchangeRate = getPlanExchangeRateById(supplierOrder.getCurrencyId());
        BigDecimal standardAmount = supplierOrder.getTotalFee().multiply(plannedExchangeRate);
        supplierOrder.setStandardAmount(standardAmount);
        supplierOrder.setPayableAmount(supplierOrder.getTotalFee());
    }

    @Override
    public PageResponse<SupplierOrderHotelPageDTO> selectSystemHotelList(SupplierOrderSystemHotelPageReq supplierOrderSystemHotelPageReq) {
        Page<SupplierOrder> supplierOutsideOrderAirPage = new Page<>(supplierOrderSystemHotelPageReq.getPageNo(), supplierOrderSystemHotelPageReq.getPageSize());
        QueryWrapper<SupplierOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SupplierOrder::getReserveTypeId, SupplierReserveTypeEnum.HOTEL.getId());
        queryWrapper.lambda().eq(SupplierOrder::getBusinessType, SystemBusinessType.HOTEL.getCode());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemHotelPageReq.getOrderNumber()), SupplierOrder::getOrderNumber, supplierOrderSystemHotelPageReq.getOrderNumber());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemHotelPageReq.getSaleNumber()), SupplierOrder::getSaleNumber, supplierOrderSystemHotelPageReq.getSaleNumber());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemHotelPageReq.getSupplierName()), SupplierOrder::getSupplierName, supplierOrderSystemHotelPageReq.getSupplierName());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemHotelPageReq.getProductName()), SupplierOrder::getProductName, supplierOrderSystemHotelPageReq.getProductName());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemHotelPageReq.getProductNumber()), SupplierOrder::getProductNumber, supplierOrderSystemHotelPageReq.getProductNumber());
        queryWrapper.lambda().ge(supplierOrderSystemHotelPageReq.getFromGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderSystemHotelPageReq.getFromGmtCreate());
        queryWrapper.lambda().le(supplierOrderSystemHotelPageReq.getToGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderSystemHotelPageReq.getToGmtCreate());
        queryWrapper.lambda().ge(supplierOrderSystemHotelPageReq.getFromExpectedPayTime() != null, SupplierOrder::getExpectedPayTime, supplierOrderSystemHotelPageReq.getFromExpectedPayTime());
        queryWrapper.lambda().le(supplierOrderSystemHotelPageReq.getToExpectedPayTime() != null, SupplierOrder::getExpectedPayTime, supplierOrderSystemHotelPageReq.getToExpectedPayTime());
        queryWrapper.lambda().eq(supplierOrderSystemHotelPageReq.getVerifyStatus() != null, SupplierOrder::getVerifyStatus, supplierOrderSystemHotelPageReq.getVerifyStatus());
        queryWrapper.lambda().eq(supplierOrderSystemHotelPageReq.getReserveStatus() != null, SupplierOrder::getReserveStatus, supplierOrderSystemHotelPageReq.getReserveStatus());
        queryWrapper.lambda().eq(supplierOrderSystemHotelPageReq.getProductType() != null, SupplierOrder::getProductType, supplierOrderSystemHotelPageReq.getProductType());
        queryWrapper.lambda().eq(supplierOrderSystemHotelPageReq.getSubmitSettleStatus() != null, SupplierOrder::getSubmitSettleStatus, supplierOrderSystemHotelPageReq.getSubmitSettleStatus());
        queryWrapper.lambda().orderByDesc(SupplierOrder::getGmtCreate);
        //do something缺少销售字段查询
        Page<SupplierOrder> iPage = supplierOrderMapper.selectPage(supplierOutsideOrderAirPage, queryWrapper);
        List<SupplierOrder> records = iPage.getRecords();
        if (CollectionUtils.isEmpty(records)) {
            return new PageResponse<>(new ArrayList<>(), iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
        }
        List<SupplierOrderHotelPageDTO> supplierOutsideOrderAirQueryDTOList = EntityUtil.copyList(records, SupplierOrderHotelPageDTO.class);
        for (SupplierOrderHotelPageDTO supplierOrderHotelPageDTO : supplierOutsideOrderAirQueryDTOList) {
            UserDTO userDTO = sysUserService.queryCacheUser(supplierOrderHotelPageDTO.getCreateId());
            supplierOrderHotelPageDTO.setCreateUser(userDTO.getCreateDept());
        }
        return new PageResponse<>(supplierOutsideOrderAirQueryDTOList, iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
    }

    @Override
    public SupplierOrderSystemHotelInfoDTO getSystemHotel(Long id) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(id);
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_HOTEL_13501);
        }
        List<SupplierSystemOrderHotelCheckInInfoDTO> supplierSystemOrderHotelCheckInInfoDTOList = supplierSystemOrderHotelCheckInService.selectByOrderId(id);
        SupplierOrderSystemHotelInfoDTO supplierOrderSystemHotelInfoDTO = EntityUtil.copy(supplierOrder, SupplierOrderSystemHotelInfoDTO.class);
        supplierOrderSystemHotelInfoDTO.setSupplierSystemOrderHotelCheckInInfoDTOList(supplierSystemOrderHotelCheckInInfoDTOList);
        return supplierOrderSystemHotelInfoDTO;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result<Long> editSystemAir(SupplierOrderSystemAirEditReq supplierOrderSystemAirEditReq, Long userId) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(supplierOrderSystemAirEditReq.getId());
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_HOTEL_13501);
        }
        LocalDateTime nowDateTime = LocalDateTime.now();
        supplierOrder.setModifiedId(userId);
        supplierOrder.setGmtModified(nowDateTime);
        updateSystemOrder(supplierOrder);
        supplierSystemOrderAirService.update(userId, nowDateTime, supplierOrderSystemAirEditReq.getSupplierSystemOrderAirEditReqList());
        return Result.success(supplierOrderSystemAirEditReq.getId());
    }

    @Override
    public Result<Long> addSystemAir(SupplierOrderSystemAirAddReq supplierOrderSystemAirAddReq, Long userId) {
        log.info("【供应商预订-新增系统机票】入参:{},用户ID:{}", JSON.toJSONString(supplierOrderSystemAirAddReq), userId);
        ValidatorUtil.validate(supplierOrderSystemAirAddReq);
        SupplierOrder supplierOrder = EntityUtil.copy(supplierOrderSystemAirAddReq, SupplierOrder.class);
        LocalDateTime nowDateTime = LocalDateTime.now();

        // 构建供应商预订单-供应商数据
        buildSystemSupplier(supplierOrder, nowDateTime);
        // 构建供应商预订单-状态数据
        buildSupplierBookingOrder(supplierOrder, SupplierReserveTypeEnum.AIR);
        /**
         * 构建内部挂账供应商预订单
         */
        saveInnerSupplierOrder(supplierOrder, userId, nowDateTime);
        saveSupplierOrder(userId, nowDateTime, supplierOrder);
        supplierSystemOrderAirService.add(supplierOrder.getId(), userId, nowDateTime, supplierOrderSystemAirAddReq.getSupplierSystemOrderAirAddReqList());
        return Result.success(supplierOrder.getId());
    }

    @Override
    public PageResponse<SupplierOrderAirPageDTO> selectSystemAirList(SupplierOrderSystemAirPageReq supplierOrderSystemAirPageReq) {
        Page<SupplierOrder> supplierOutsideOrderAirPage = new Page<>(supplierOrderSystemAirPageReq.getPageNo(), supplierOrderSystemAirPageReq.getPageSize());
        QueryWrapper<SupplierOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SupplierOrder::getReserveTypeId, SupplierReserveTypeEnum.AIR.getId());
        queryWrapper.lambda().eq(SupplierOrder::getBusinessType, SystemBusinessType.AIR_TICKET.getCode());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemAirPageReq.getOrderNumber()), SupplierOrder::getOrderNumber, supplierOrderSystemAirPageReq.getOrderNumber());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemAirPageReq.getSaleNumber()), SupplierOrder::getSaleNumber, supplierOrderSystemAirPageReq.getSaleNumber());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemAirPageReq.getSupplierName()), SupplierOrder::getSupplierName, supplierOrderSystemAirPageReq.getSupplierName());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemAirPageReq.getProductName()), SupplierOrder::getProductName, supplierOrderSystemAirPageReq.getProductName());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemAirPageReq.getProductNumber()), SupplierOrder::getProductNumber, supplierOrderSystemAirPageReq.getProductNumber());
        queryWrapper.lambda().ge(supplierOrderSystemAirPageReq.getFromGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderSystemAirPageReq.getFromGmtCreate());
        queryWrapper.lambda().le(supplierOrderSystemAirPageReq.getToGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderSystemAirPageReq.getToGmtCreate());
        queryWrapper.lambda().ge(supplierOrderSystemAirPageReq.getFromExpectedPayTime() != null, SupplierOrder::getExpectedPayTime, supplierOrderSystemAirPageReq.getFromExpectedPayTime());
        queryWrapper.lambda().le(supplierOrderSystemAirPageReq.getToExpectedPayTime() != null, SupplierOrder::getExpectedPayTime, supplierOrderSystemAirPageReq.getToExpectedPayTime());
        queryWrapper.lambda().eq(supplierOrderSystemAirPageReq.getVerifyStatus() != null, SupplierOrder::getVerifyStatus, supplierOrderSystemAirPageReq.getVerifyStatus());
        queryWrapper.lambda().eq(supplierOrderSystemAirPageReq.getReserveStatus() != null, SupplierOrder::getReserveStatus, supplierOrderSystemAirPageReq.getReserveStatus());
        queryWrapper.lambda().eq(supplierOrderSystemAirPageReq.getProductType() != null, SupplierOrder::getProductType, supplierOrderSystemAirPageReq.getProductType());
        queryWrapper.lambda().eq(supplierOrderSystemAirPageReq.getSubmitSettleStatus() != null, SupplierOrder::getSubmitSettleStatus, supplierOrderSystemAirPageReq.getSubmitSettleStatus());
        queryWrapper.lambda().orderByDesc(SupplierOrder::getGmtCreate);
        //do something缺少销售字段查询
        Page<SupplierOrder> iPage = supplierOrderMapper.selectPage(supplierOutsideOrderAirPage, queryWrapper);
        List<SupplierOrder> records = iPage.getRecords();
        if (CollectionUtils.isEmpty(records)) {
            return new PageResponse<>(new ArrayList<>(), iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
        }
        List<SupplierOrderAirPageDTO> supplierOutsideOrderAirQueryDTOList = EntityUtil.copyList(records, SupplierOrderAirPageDTO.class);
        for (SupplierOrderAirPageDTO supplierOrderAirPageDTO : supplierOutsideOrderAirQueryDTOList) {
            UserDTO userDTO = sysUserService.queryCacheUser(supplierOrderAirPageDTO.getCreateId());
            supplierOrderAirPageDTO.setCreateUser(userDTO.getCreateDept());
        }
        return new PageResponse<>(supplierOutsideOrderAirQueryDTOList, iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
    }

    @Override
    public SupplierOrderSystemAirInfoDTO getSystemAir(Long id) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(id);
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_HOTEL_13501);
        }
        List<SupplierSystemOrderAirInfoDTO> supplierSystemOrderAirInfoDTOList = supplierSystemOrderAirService.selectByOrderId(id);
        SupplierOrderSystemAirInfoDTO supplierOrderSystemAirInfoDTO = EntityUtil.copy(supplierOrder, SupplierOrderSystemAirInfoDTO.class);
        supplierOrderSystemAirInfoDTO.setSupplierSystemOrderAirInfoDTOList(supplierSystemOrderAirInfoDTOList);
        return supplierOrderSystemAirInfoDTO;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result<Long> editSystemTrain(SupplierOrderSystemTrainEditReq supplierOrderSystemTrainEditReq, Long userId) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(supplierOrderSystemTrainEditReq.getId());
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_HOTEL_13501);
        }
        LocalDateTime nowDateTime = LocalDateTime.now();
        supplierOrder.setModifiedId(userId);
        supplierOrder.setGmtModified(nowDateTime);
        updateSystemOrder(supplierOrder);
        supplierSystemOrderTrainService.update(userId, nowDateTime, supplierOrderSystemTrainEditReq.getSupplierSystemOrderTrainEditReqList());
        return Result.success(supplierOrderSystemTrainEditReq.getId());
    }

    @Override
    public Result<Long> addSystemTrain(SupplierOrderSystemTrainAddReq supplierOrderSystemTrainAddReq, Long userId) {
        log.info("【供应商预订-新增系统火车】入参:{},用户ID:{}", JSON.toJSONString(supplierOrderSystemTrainAddReq), userId);
        ValidatorUtil.validate(supplierOrderSystemTrainAddReq);
        SupplierOrder supplierOrder = EntityUtil.copy(supplierOrderSystemTrainAddReq, SupplierOrder.class);
        LocalDateTime nowDateTime = LocalDateTime.now();

        // 构建供应商预订单-供应商数据
        buildSystemSupplier(supplierOrder, nowDateTime);
        // 构建供应商预订单-状态数据
        buildSupplierBookingOrder(supplierOrder, SupplierReserveTypeEnum.TRAIN);
        /**
         * 构建内部挂账供应商预订单
         */
        saveInnerSupplierOrder(supplierOrder, userId, nowDateTime);
        saveSupplierOrder(userId, nowDateTime, supplierOrder);
        supplierSystemOrderTrainService.add(supplierOrder.getId(), userId, nowDateTime, supplierOrderSystemTrainAddReq.getSupplierSystemOrderTrainAddReqList());
        return Result.success(supplierOrder.getId());
    }

    @Override
    public PageResponse<SupplierOrderTrainPageDTO> selectSystemTrainList(SupplierOrderSystemTrainPageReq supplierOrderSystemTrainPageReq) {
        Page<SupplierOrder> supplierOutsideOrderAirPage = new Page<>(supplierOrderSystemTrainPageReq.getPageNo(), supplierOrderSystemTrainPageReq.getPageSize());
        QueryWrapper<SupplierOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SupplierOrder::getReserveTypeId, SupplierReserveTypeEnum.TRAIN.getId());
        queryWrapper.lambda().eq(SupplierOrder::getBusinessType, SystemBusinessType.TRAIN_TICKET.getCode());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemTrainPageReq.getOrderNumber()), SupplierOrder::getOrderNumber, supplierOrderSystemTrainPageReq.getOrderNumber());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemTrainPageReq.getSaleNumber()), SupplierOrder::getSaleNumber, supplierOrderSystemTrainPageReq.getSaleNumber());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemTrainPageReq.getSupplierName()), SupplierOrder::getSupplierName, supplierOrderSystemTrainPageReq.getSupplierName());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemTrainPageReq.getProductName()), SupplierOrder::getProductName, supplierOrderSystemTrainPageReq.getProductName());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemTrainPageReq.getProductNumber()), SupplierOrder::getProductNumber, supplierOrderSystemTrainPageReq.getProductNumber());
        queryWrapper.lambda().ge(supplierOrderSystemTrainPageReq.getFromGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderSystemTrainPageReq.getFromGmtCreate());
        queryWrapper.lambda().le(supplierOrderSystemTrainPageReq.getToGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderSystemTrainPageReq.getToGmtCreate());
        queryWrapper.lambda().ge(supplierOrderSystemTrainPageReq.getFromExpectedPayTime() != null, SupplierOrder::getExpectedPayTime, supplierOrderSystemTrainPageReq.getFromExpectedPayTime());
        queryWrapper.lambda().le(supplierOrderSystemTrainPageReq.getToExpectedPayTime() != null, SupplierOrder::getExpectedPayTime, supplierOrderSystemTrainPageReq.getToExpectedPayTime());
        queryWrapper.lambda().eq(supplierOrderSystemTrainPageReq.getVerifyStatus() != null, SupplierOrder::getVerifyStatus, supplierOrderSystemTrainPageReq.getVerifyStatus());
        queryWrapper.lambda().eq(supplierOrderSystemTrainPageReq.getReserveStatus() != null, SupplierOrder::getReserveStatus, supplierOrderSystemTrainPageReq.getReserveStatus());
        queryWrapper.lambda().eq(supplierOrderSystemTrainPageReq.getProductType() != null, SupplierOrder::getProductType, supplierOrderSystemTrainPageReq.getProductType());
        queryWrapper.lambda().eq(supplierOrderSystemTrainPageReq.getSubmitSettleStatus() != null, SupplierOrder::getSubmitSettleStatus, supplierOrderSystemTrainPageReq.getSubmitSettleStatus());
        queryWrapper.lambda().orderByDesc(SupplierOrder::getGmtCreate);
        //do something缺少销售字段查询
        Page<SupplierOrder> iPage = supplierOrderMapper.selectPage(supplierOutsideOrderAirPage, queryWrapper);
        List<SupplierOrder> records = iPage.getRecords();
        if (CollectionUtils.isEmpty(records)) {
            return new PageResponse<>(new ArrayList<>(), iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
        }
        List<SupplierOrderTrainPageDTO> supplierOutsideOrderAirQueryDTOList = EntityUtil.copyList(records, SupplierOrderTrainPageDTO.class);
        for (SupplierOrderTrainPageDTO supplierOrderTrainPageDTO : supplierOutsideOrderAirQueryDTOList) {
            UserDTO userDTO = sysUserService.queryCacheUser(supplierOrderTrainPageDTO.getCreateId());
            supplierOrderTrainPageDTO.setCreateUser(userDTO.getCreateDept());
        }
        return new PageResponse<>(supplierOutsideOrderAirQueryDTOList, iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
    }

    @Override
    public SupplierOrderSystemTrainInfoDTO getSystemTrain(Long id) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(id);
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_HOTEL_13501);
        }
        List<SupplierSystemOrderTrainInfoDTO> supplierSystemOrderTrainCheckInInfoDTOList = supplierSystemOrderTrainService.selectByOrderId(id);
        SupplierOrderSystemTrainInfoDTO supplierOrderSystemTrainInfoDTO = EntityUtil.copy(supplierOrder, SupplierOrderSystemTrainInfoDTO.class);
        supplierOrderSystemTrainInfoDTO.setSupplierSystemOrderTrainInfoDTOList(supplierSystemOrderTrainCheckInInfoDTOList);
        return supplierOrderSystemTrainInfoDTO;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result<Long> editSystemBus(SupplierOrderSystemBusEditReq supplierOrderSystemBusEditReq, Long userId) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(supplierOrderSystemBusEditReq.getId());
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_HOTEL_13501);
        }
        LocalDateTime nowDateTime = LocalDateTime.now();
        supplierOrder.setModifiedId(userId);
        supplierOrder.setGmtModified(nowDateTime);
        updateSystemOrder(supplierOrder);
        supplierSystemOrderBusService.update(userId, nowDateTime, supplierOrderSystemBusEditReq.getSupplierSystemOrderBusEditReqList());
        return Result.success(supplierOrderSystemBusEditReq.getId());
    }

    @Override
    public Result<Long> addSystemBus(SupplierOrderSystemBusAddReq supplierOrderSystemBusAddReq, Long userId) {
        log.info("【供应商预订-新增系统巴士】入参:{},用户ID:{}", JSON.toJSONString(supplierOrderSystemBusAddReq), userId);
        ValidatorUtil.validate(supplierOrderSystemBusAddReq);
        SupplierOrder supplierOrder = EntityUtil.copy(supplierOrderSystemBusAddReq, SupplierOrder.class);
        LocalDateTime nowDateTime = LocalDateTime.now();

        // 构建供应商预订单-供应商数据
        buildSystemSupplier(supplierOrder, nowDateTime);
        // 构建供应商预订单-状态数据
        buildSupplierBookingOrder(supplierOrder, SupplierReserveTypeEnum.BUS);
        /**
         * 构建内部挂账供应商预订单
         */
        saveInnerSupplierOrder(supplierOrder, userId, nowDateTime);
        saveSupplierOrder(userId, nowDateTime, supplierOrder);
        supplierSystemOrderBusService.add(supplierOrder.getId(), userId, nowDateTime, supplierOrderSystemBusAddReq.getSupplierSystemOrderBusAddReqList());
        return Result.success(supplierOrder.getId());
    }

    @Override
    public PageResponse<SupplierOrderBusPageDTO> selectSystemBusList(SupplierOrderSystemBusPageReq supplierOrderSystemBusPageReq) {
        Page<SupplierOrder> supplierOutsideOrderAirPage = new Page<>(supplierOrderSystemBusPageReq.getPageNo(), supplierOrderSystemBusPageReq.getPageSize());
        QueryWrapper<SupplierOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SupplierOrder::getReserveTypeId, SupplierReserveTypeEnum.BUS.getId());
        queryWrapper.lambda().eq(SupplierOrder::getBusinessType, SystemBusinessType.BUS_TICKET.getCode());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemBusPageReq.getOrderNumber()), SupplierOrder::getOrderNumber, supplierOrderSystemBusPageReq.getOrderNumber());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemBusPageReq.getSaleNumber()), SupplierOrder::getSaleNumber, supplierOrderSystemBusPageReq.getSaleNumber());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemBusPageReq.getSupplierName()), SupplierOrder::getSupplierName, supplierOrderSystemBusPageReq.getSupplierName());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemBusPageReq.getProductName()), SupplierOrder::getProductName, supplierOrderSystemBusPageReq.getProductName());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemBusPageReq.getProductNumber()), SupplierOrder::getProductNumber, supplierOrderSystemBusPageReq.getProductNumber());
        queryWrapper.lambda().ge(supplierOrderSystemBusPageReq.getFromGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderSystemBusPageReq.getFromGmtCreate());
        queryWrapper.lambda().le(supplierOrderSystemBusPageReq.getToGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderSystemBusPageReq.getToGmtCreate());
        queryWrapper.lambda().ge(supplierOrderSystemBusPageReq.getFromExpectedPayTime() != null, SupplierOrder::getExpectedPayTime, supplierOrderSystemBusPageReq.getFromExpectedPayTime());
        queryWrapper.lambda().le(supplierOrderSystemBusPageReq.getToExpectedPayTime() != null, SupplierOrder::getExpectedPayTime, supplierOrderSystemBusPageReq.getToExpectedPayTime());
        queryWrapper.lambda().eq(supplierOrderSystemBusPageReq.getVerifyStatus() != null, SupplierOrder::getVerifyStatus, supplierOrderSystemBusPageReq.getVerifyStatus());
        queryWrapper.lambda().eq(supplierOrderSystemBusPageReq.getReserveStatus() != null, SupplierOrder::getReserveStatus, supplierOrderSystemBusPageReq.getReserveStatus());
        queryWrapper.lambda().eq(supplierOrderSystemBusPageReq.getProductType() != null, SupplierOrder::getProductType, supplierOrderSystemBusPageReq.getProductType());
        queryWrapper.lambda().eq(supplierOrderSystemBusPageReq.getSubmitSettleStatus() != null, SupplierOrder::getSubmitSettleStatus, supplierOrderSystemBusPageReq.getSubmitSettleStatus());
        queryWrapper.lambda().orderByDesc(SupplierOrder::getGmtCreate);
        //do something缺少销售字段查询
        Page<SupplierOrder> iPage = supplierOrderMapper.selectPage(supplierOutsideOrderAirPage, queryWrapper);
        List<SupplierOrder> records = iPage.getRecords();
        if (CollectionUtils.isEmpty(records)) {
            return new PageResponse<>(new ArrayList<>(), iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
        }
        List<SupplierOrderBusPageDTO> supplierOutsideOrderAirQueryDTOList = EntityUtil.copyList(records, SupplierOrderBusPageDTO.class);
        for (SupplierOrderBusPageDTO supplierOrderBusPageDTO : supplierOutsideOrderAirQueryDTOList) {
            UserDTO userDTO = sysUserService.queryCacheUser(supplierOrderBusPageDTO.getCreateId());
            supplierOrderBusPageDTO.setCreateUser(userDTO.getCreateDept());
        }
        return new PageResponse<>(supplierOutsideOrderAirQueryDTOList, iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
    }

    @Override
    public SupplierOrderSystemBusInfoDTO getSystemBus(Long id) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(id);
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_HOTEL_13501);
        }
        List<SupplierSystemOrderBusInfoDTO> supplierSystemOrderBusCheckInInfoDTOList = supplierSystemOrderBusService.selectByOrderId(id);
        SupplierOrderSystemBusInfoDTO supplierOrderSystemBusInfoDTO = EntityUtil.copy(supplierOrder, SupplierOrderSystemBusInfoDTO.class);
        supplierOrderSystemBusInfoDTO.setSupplierSystemOrderBusInfoDTOList(supplierSystemOrderBusCheckInInfoDTOList);
        return supplierOrderSystemBusInfoDTO;
    }

    @Override
    public PageResponse<SupplierOrderShipPageDTO> selectSystemShipList(SupplierOrderSystemShipPageReq supplierOrderSystemShipPageReq) {
        Page<SupplierOrder> supplierOutsideOrderAirPage = new Page<>(supplierOrderSystemShipPageReq.getPageNo(), supplierOrderSystemShipPageReq.getPageSize());
        QueryWrapper<SupplierOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SupplierOrder::getReserveTypeId, SupplierReserveTypeEnum.SHIP.getId());
        queryWrapper.lambda().eq(SupplierOrder::getBusinessType, SystemBusinessType.SHIP_TICKET.getCode());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemShipPageReq.getOrderNumber()), SupplierOrder::getOrderNumber, supplierOrderSystemShipPageReq.getOrderNumber());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemShipPageReq.getSaleNumber()), SupplierOrder::getSaleNumber, supplierOrderSystemShipPageReq.getSaleNumber());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemShipPageReq.getSupplierName()), SupplierOrder::getSupplierName, supplierOrderSystemShipPageReq.getSupplierName());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemShipPageReq.getProductName()), SupplierOrder::getProductName, supplierOrderSystemShipPageReq.getProductName());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemShipPageReq.getProductNumber()), SupplierOrder::getProductNumber, supplierOrderSystemShipPageReq.getProductNumber());
        queryWrapper.lambda().ge(supplierOrderSystemShipPageReq.getFromGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderSystemShipPageReq.getFromGmtCreate());
        queryWrapper.lambda().le(supplierOrderSystemShipPageReq.getToGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderSystemShipPageReq.getToGmtCreate());
        queryWrapper.lambda().ge(supplierOrderSystemShipPageReq.getFromExpectedPayTime() != null, SupplierOrder::getExpectedPayTime, supplierOrderSystemShipPageReq.getFromExpectedPayTime());
        queryWrapper.lambda().le(supplierOrderSystemShipPageReq.getToExpectedPayTime() != null, SupplierOrder::getExpectedPayTime, supplierOrderSystemShipPageReq.getToExpectedPayTime());
        queryWrapper.lambda().eq(supplierOrderSystemShipPageReq.getVerifyStatus() != null, SupplierOrder::getVerifyStatus, supplierOrderSystemShipPageReq.getVerifyStatus());
        queryWrapper.lambda().eq(supplierOrderSystemShipPageReq.getReserveStatus() != null, SupplierOrder::getReserveStatus, supplierOrderSystemShipPageReq.getReserveStatus());
        queryWrapper.lambda().eq(supplierOrderSystemShipPageReq.getProductType() != null, SupplierOrder::getProductType, supplierOrderSystemShipPageReq.getProductType());
        queryWrapper.lambda().eq(supplierOrderSystemShipPageReq.getSubmitSettleStatus() != null, SupplierOrder::getSubmitSettleStatus, supplierOrderSystemShipPageReq.getSubmitSettleStatus());
        queryWrapper.lambda().orderByDesc(SupplierOrder::getGmtCreate);
        //do something缺少销售字段查询
        Page<SupplierOrder> iPage = supplierOrderMapper.selectPage(supplierOutsideOrderAirPage, queryWrapper);
        List<SupplierOrder> records = iPage.getRecords();
        if (CollectionUtils.isEmpty(records)) {
            return new PageResponse<>(new ArrayList<>(), iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
        }
        List<SupplierOrderShipPageDTO> supplierOutsideOrderAirQueryDTOList = EntityUtil.copyList(records, SupplierOrderShipPageDTO.class);
        for (SupplierOrderShipPageDTO supplierOrderShipPageDTO : supplierOutsideOrderAirQueryDTOList) {
            UserDTO userDTO = sysUserService.queryCacheUser(supplierOrderShipPageDTO.getCreateId());
            supplierOrderShipPageDTO.setCreateUser(userDTO.getCreateDept());
        }
        return new PageResponse<>(supplierOutsideOrderAirQueryDTOList, iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
    }

    @Override
    public Result<Long> addSystemShip(SupplierOrderSystemShipAddReq supplierOrderSystemShipAddReq, Long userId) {
        log.info("【供应商预订-新增系统船票】入参:{},用户ID:{}", JSON.toJSONString(supplierOrderSystemShipAddReq), userId);
        ValidatorUtil.validate(supplierOrderSystemShipAddReq);
        SupplierOrder supplierOrder = EntityUtil.copy(supplierOrderSystemShipAddReq, SupplierOrder.class);
        LocalDateTime nowDateTime = LocalDateTime.now();

        // 构建供应商预订单-供应商数据
        buildSystemSupplier(supplierOrder, nowDateTime);
        // 构建供应商预订单-状态数据
        buildSupplierBookingOrder(supplierOrder, SupplierReserveTypeEnum.SHIP);
        /**
         * 构建内部挂账供应商预订单
         */
        saveInnerSupplierOrder(supplierOrder, userId, nowDateTime);
        saveSupplierOrder(userId, nowDateTime, supplierOrder);
        supplierSystemOrderShipService.add(supplierOrder.getId(), userId, nowDateTime, supplierOrderSystemShipAddReq.getSupplierSystemOrderShipAddReq());
        return Result.success(supplierOrder.getId());
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result<Long> editSystemShip(SupplierOrderSystemShipEditReq supplierOrderSystemShipEditReq, Long userId) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(supplierOrderSystemShipEditReq.getId());
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_HOTEL_13501);
        }
        LocalDateTime nowDateTime = LocalDateTime.now();
        supplierOrder.setModifiedId(userId);
        supplierOrder.setGmtModified(nowDateTime);
        updateSystemOrder(supplierOrder);
        supplierSystemOrderShipService.update(userId, nowDateTime, supplierOrderSystemShipEditReq.getSupplierSystemOrderShipEditReq());
        return Result.success(supplierOrderSystemShipEditReq.getId());
    }

    @Override
    public SupplierOrderSystemShipInfoDTO getSystemShip(Long id) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(id);
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_HOTEL_13501);
        }
        List<SupplierSystemOrderShipInfoDTO> supplierSystemOrderShipCheckInInfoDTOList = supplierSystemOrderShipService.selectByOrderId(id);
        SupplierOrderSystemShipInfoDTO supplierOrderSystemShipInfoDTO = EntityUtil.copy(supplierOrder, SupplierOrderSystemShipInfoDTO.class);
        supplierOrderSystemShipInfoDTO.setSupplierSystemOrderShipInfoDTOList(supplierSystemOrderShipCheckInInfoDTOList);
        return supplierOrderSystemShipInfoDTO;
    }

    @Override
    public PageResponse<SupplierOrderAdmissionPageDTO> selectSystemAdmissionList(SupplierOrderSystemAdmissionPageReq supplierOrderSystemAdmissionPageReq) {
        Page<SupplierOrder> supplierOutsideOrderAdmissionPage = new Page<>(supplierOrderSystemAdmissionPageReq.getPageNo(), supplierOrderSystemAdmissionPageReq.getPageSize());
        QueryWrapper<SupplierOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SupplierOrder::getReserveTypeId, SupplierReserveTypeEnum.SCENIC.getId());
        queryWrapper.lambda().eq(SupplierOrder::getBusinessType, SystemBusinessType.ATTRACTION_TICKET.getCode());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemAdmissionPageReq.getOrderNumber()), SupplierOrder::getOrderNumber, supplierOrderSystemAdmissionPageReq.getOrderNumber());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemAdmissionPageReq.getSaleNumber()), SupplierOrder::getSaleNumber, supplierOrderSystemAdmissionPageReq.getSaleNumber());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemAdmissionPageReq.getSupplierName()), SupplierOrder::getSupplierName, supplierOrderSystemAdmissionPageReq.getSupplierName());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemAdmissionPageReq.getProductName()), SupplierOrder::getProductName, supplierOrderSystemAdmissionPageReq.getProductName());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemAdmissionPageReq.getProductNumber()), SupplierOrder::getProductNumber, supplierOrderSystemAdmissionPageReq.getProductNumber());
        queryWrapper.lambda().ge(supplierOrderSystemAdmissionPageReq.getFromGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderSystemAdmissionPageReq.getFromGmtCreate());
        queryWrapper.lambda().le(supplierOrderSystemAdmissionPageReq.getToGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderSystemAdmissionPageReq.getToGmtCreate());
        queryWrapper.lambda().ge(supplierOrderSystemAdmissionPageReq.getFromExpectedPayTime() != null, SupplierOrder::getExpectedPayTime, supplierOrderSystemAdmissionPageReq.getFromExpectedPayTime());
        queryWrapper.lambda().le(supplierOrderSystemAdmissionPageReq.getToExpectedPayTime() != null, SupplierOrder::getExpectedPayTime, supplierOrderSystemAdmissionPageReq.getToExpectedPayTime());
        queryWrapper.lambda().eq(supplierOrderSystemAdmissionPageReq.getVerifyStatus() != null, SupplierOrder::getVerifyStatus, supplierOrderSystemAdmissionPageReq.getVerifyStatus());
        queryWrapper.lambda().eq(supplierOrderSystemAdmissionPageReq.getReserveStatus() != null, SupplierOrder::getReserveStatus, supplierOrderSystemAdmissionPageReq.getReserveStatus());
        queryWrapper.lambda().eq(supplierOrderSystemAdmissionPageReq.getProductType() != null, SupplierOrder::getProductType, supplierOrderSystemAdmissionPageReq.getProductType());
        queryWrapper.lambda().eq(supplierOrderSystemAdmissionPageReq.getSubmitSettleStatus() != null, SupplierOrder::getSubmitSettleStatus, supplierOrderSystemAdmissionPageReq.getSubmitSettleStatus());
        queryWrapper.lambda().orderByDesc(SupplierOrder::getGmtCreate);
        //do something缺少销售字段查询
        Page<SupplierOrder> iPage = supplierOrderMapper.selectPage(supplierOutsideOrderAdmissionPage, queryWrapper);
        List<SupplierOrder> records = iPage.getRecords();
        if (CollectionUtils.isEmpty(records)) {
            return new PageResponse<>(new ArrayList<>(), iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
        }
        List<SupplierOrderAdmissionPageDTO> supplierOutsideOrderAirQueryDTOList = EntityUtil.copyList(records, SupplierOrderAdmissionPageDTO.class);
        for (SupplierOrderAdmissionPageDTO supplierOrderAdmissionPageDTO : supplierOutsideOrderAirQueryDTOList) {
            UserDTO userDTO = sysUserService.queryCacheUser(supplierOrderAdmissionPageDTO.getCreateId());
            supplierOrderAdmissionPageDTO.setCreateUser(userDTO.getCreateDept());
        }
        return new PageResponse<>(supplierOutsideOrderAirQueryDTOList, iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
    }

    @Override
    public Result<Long> addSystemAdmission(SupplierOrderSystemAdmissionAddReq supplierOrderSystemAdmissionAddReq, Long userId) {
        log.info("【供应商预订-新增系统景点门票】入参:{},用户ID:{}", JSON.toJSONString(supplierOrderSystemAdmissionAddReq), userId);
        ValidatorUtil.validate(supplierOrderSystemAdmissionAddReq);
        SupplierOrder supplierOrder = EntityUtil.copy(supplierOrderSystemAdmissionAddReq, SupplierOrder.class);
        LocalDateTime nowDateTime = LocalDateTime.now();

        // 构建供应商预订单-供应商数据
        buildSystemSupplier(supplierOrder, nowDateTime);
        // 构建供应商预订单-状态数据
        buildSupplierBookingOrder(supplierOrder, SupplierReserveTypeEnum.SCENIC);
        /**
         * 构建内部挂账供应商预订单
         */
        saveInnerSupplierOrder(supplierOrder, userId, nowDateTime);
        saveSupplierOrder(userId, nowDateTime, supplierOrder);
        supplierSystemOrderAdmissionTicketService.add(supplierOrder.getId(), userId, nowDateTime, supplierOrderSystemAdmissionAddReq.getSupplierSystemOrderAdmissionAddReqList());
        return Result.success(supplierOrder.getId());
    }

    @Override
    public Result<Long> editSystemAdmission(SupplierOrderSystemAdmissionEditReq supplierOrderSystemAdmissionEditReq, Long userId) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(supplierOrderSystemAdmissionEditReq.getId());
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_HOTEL_13501);
        }
        LocalDateTime nowDateTime = LocalDateTime.now();
        supplierOrder.setModifiedId(userId);
        supplierOrder.setGmtModified(nowDateTime);
        updateSystemOrder(supplierOrder);
        supplierSystemOrderAdmissionTicketService.update(userId, nowDateTime, supplierOrderSystemAdmissionEditReq.getSupplierSystemOrderAdmissionEditReqList());
        return Result.success(supplierOrderSystemAdmissionEditReq.getId());
    }

    @Override
    public SupplierOrderSystemAdmissionInfoDTO getSystemAdmission(Long id) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(id);
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_HOTEL_13501);
        }
        List<SupplierSystemOrderAdmissionTicketInfoDTO> supplierSystemOrderAdmissionTicketInfoDTOList = supplierSystemOrderAdmissionTicketService.selectByOrderId(id);
        SupplierOrderSystemAdmissionInfoDTO supplierOrderSystemAdmissionInfoDTO = EntityUtil.copy(supplierOrder, SupplierOrderSystemAdmissionInfoDTO.class);
        supplierOrderSystemAdmissionInfoDTO.setSupplierSystemOrderAdmissionTicketInfoDTOList(supplierSystemOrderAdmissionTicketInfoDTOList);
        return supplierOrderSystemAdmissionInfoDTO;
    }

    @Override
    public PageResponse<SupplierOrderInsurancePageDTO> selectSystemInsuranceList(SupplierOrderSystemInsurancePageReq supplierOrderSystemInsurancePageReq) {
        Page<SupplierOrder> supplierOutsideOrderAirPage = new Page<>(supplierOrderSystemInsurancePageReq.getPageNo(), supplierOrderSystemInsurancePageReq.getPageSize());
        QueryWrapper<SupplierOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SupplierOrder::getReserveTypeId, SupplierReserveTypeEnum.INSURANCE.getId());
//        queryWrapper.lambda().eq(SupplierOrder::getBusinessType, SystemBusinessType.INSURANCE.getCode());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemInsurancePageReq.getOrderNumber()), SupplierOrder::getOrderNumber, supplierOrderSystemInsurancePageReq.getOrderNumber());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemInsurancePageReq.getSaleNumber()), SupplierOrder::getSaleNumber, supplierOrderSystemInsurancePageReq.getSaleNumber());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemInsurancePageReq.getSupplierName()), SupplierOrder::getSupplierName, supplierOrderSystemInsurancePageReq.getSupplierName());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemInsurancePageReq.getProductName()), SupplierOrder::getProductName, supplierOrderSystemInsurancePageReq.getProductName());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemInsurancePageReq.getProductNumber()), SupplierOrder::getProductNumber, supplierOrderSystemInsurancePageReq.getProductNumber());
        queryWrapper.lambda().ge(supplierOrderSystemInsurancePageReq.getFromGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderSystemInsurancePageReq.getFromGmtCreate());
        queryWrapper.lambda().le(supplierOrderSystemInsurancePageReq.getToGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderSystemInsurancePageReq.getToGmtCreate());
        queryWrapper.lambda().ge(supplierOrderSystemInsurancePageReq.getFromExpectedPayTime() != null, SupplierOrder::getExpectedPayTime, supplierOrderSystemInsurancePageReq.getFromExpectedPayTime());
        queryWrapper.lambda().le(supplierOrderSystemInsurancePageReq.getToExpectedPayTime() != null, SupplierOrder::getExpectedPayTime, supplierOrderSystemInsurancePageReq.getToExpectedPayTime());
        queryWrapper.lambda().eq(supplierOrderSystemInsurancePageReq.getVerifyStatus() != null, SupplierOrder::getVerifyStatus, supplierOrderSystemInsurancePageReq.getVerifyStatus());
        queryWrapper.lambda().eq(supplierOrderSystemInsurancePageReq.getReserveStatus() != null, SupplierOrder::getReserveStatus, supplierOrderSystemInsurancePageReq.getReserveStatus());
        queryWrapper.lambda().eq(supplierOrderSystemInsurancePageReq.getProductType() != null, SupplierOrder::getProductType, supplierOrderSystemInsurancePageReq.getProductType());
        queryWrapper.lambda().eq(supplierOrderSystemInsurancePageReq.getSubmitSettleStatus() != null, SupplierOrder::getSubmitSettleStatus, supplierOrderSystemInsurancePageReq.getSubmitSettleStatus());
        queryWrapper.lambda().orderByDesc(SupplierOrder::getGmtCreate);
        //do something缺少销售字段查询
        Page<SupplierOrder> iPage = supplierOrderMapper.selectPage(supplierOutsideOrderAirPage, queryWrapper);
        List<SupplierOrder> records = iPage.getRecords();
        if (CollectionUtils.isEmpty(records)) {
            return new PageResponse<>(new ArrayList<>(), iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
        }
        List<SupplierOrderInsurancePageDTO> supplierOutsideOrderAirQueryDTOList = EntityUtil.copyList(records, SupplierOrderInsurancePageDTO.class);
        for (SupplierOrderInsurancePageDTO supplierOrderInsurancePageDTO : supplierOutsideOrderAirQueryDTOList) {
            UserDTO userDTO = sysUserService.queryCacheUser(supplierOrderInsurancePageDTO.getCreateId());
            supplierOrderInsurancePageDTO.setCreateUser(userDTO.getCreateDept());
        }
        return new PageResponse<>(supplierOutsideOrderAirQueryDTOList, iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result<String> addSystemInsurance(SupplierOrderSystemInsuranceAddReq supplierOrderSystemInsuranceAddReq, Long userId) {
        log.info("【供应商预订-新增系统保险】入参:{},用户ID:{}", JSON.toJSONString(supplierOrderSystemInsuranceAddReq), userId);
        ValidatorUtil.validate(supplierOrderSystemInsuranceAddReq);
        SupplierOrder supplierOrder = EntityUtil.copy(supplierOrderSystemInsuranceAddReq, SupplierOrder.class);
        LocalDateTime nowDateTime = LocalDateTime.now();

        // 构建供应商预订单-供应商数据
        buildSystemSupplier(supplierOrder, nowDateTime);
        // 构建供应商预订单-状态数据
        buildSupplierBookingOrder(supplierOrder, SupplierReserveTypeEnum.INSURANCE);
        /**
         * 构建内部挂账供应商预订单
         */
        supplierOrder.setReserveStatus(OrderScheduledStatus.RESERVE_SUCCESS.getCode());
        saveInnerSupplierOrder(supplierOrder, userId, nowDateTime);
        saveSupplierOrder(userId, nowDateTime, supplierOrder);
        supplierSystemOrderInsuranceService.add(supplierOrder.getId(), userId, nowDateTime, supplierOrderSystemInsuranceAddReq.getSupplierSystemOrderInsuranceAddReq());
        return Result.success(supplierOrder.getOrderNumber());
    }

    @Override
    public SupplierOrderSystemInsuranceInfoDTO getSystemInsurance(Long id) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(id);
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_HOTEL_13501);
        }
        List<SupplierSystemOrderInsuranceInfoDTO> supplierSystemOrderInsuranceCheckInInfoDTOList = supplierSystemOrderInsuranceService.selectByOrderId(id);
        SupplierOrderSystemInsuranceInfoDTO supplierOrderSystemInsuranceInfoDTO = EntityUtil.copy(supplierOrder, SupplierOrderSystemInsuranceInfoDTO.class);
        supplierOrderSystemInsuranceInfoDTO.setSupplierSystemOrderInsuranceInfoDTOList(supplierSystemOrderInsuranceCheckInInfoDTOList);
        return supplierOrderSystemInsuranceInfoDTO;
    }

    @Override
    public PageResponse<SupplierOrderStampDutyPageDTO> selectSystemStampDutyList(SupplierOrderSystemStampDutyPageReq supplierOrderSystemStampDutyPageReq) {
        Page<SupplierOrder> supplierOutsideOrderAirPage = new Page<>(supplierOrderSystemStampDutyPageReq.getPageNo(), supplierOrderSystemStampDutyPageReq.getPageSize());
        QueryWrapper<SupplierOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SupplierOrder::getReserveTypeId, SupplierReserveTypeEnum.STAMP_DUTY.getId());
//        queryWrapper.lambda().eq(SupplierOrder::getBusinessType, SystemBusinessType.getCode());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemStampDutyPageReq.getOrderNumber()), SupplierOrder::getOrderNumber, supplierOrderSystemStampDutyPageReq.getOrderNumber());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemStampDutyPageReq.getSaleNumber()), SupplierOrder::getSaleNumber, supplierOrderSystemStampDutyPageReq.getSaleNumber());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemStampDutyPageReq.getSupplierName()), SupplierOrder::getSupplierName, supplierOrderSystemStampDutyPageReq.getSupplierName());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemStampDutyPageReq.getProductName()), SupplierOrder::getProductName, supplierOrderSystemStampDutyPageReq.getProductName());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemStampDutyPageReq.getProductNumber()), SupplierOrder::getProductNumber, supplierOrderSystemStampDutyPageReq.getProductNumber());
        queryWrapper.lambda().ge(supplierOrderSystemStampDutyPageReq.getFromGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderSystemStampDutyPageReq.getFromGmtCreate());
        queryWrapper.lambda().le(supplierOrderSystemStampDutyPageReq.getToGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderSystemStampDutyPageReq.getToGmtCreate());
        queryWrapper.lambda().ge(supplierOrderSystemStampDutyPageReq.getFromExpectedPayTime() != null, SupplierOrder::getExpectedPayTime, supplierOrderSystemStampDutyPageReq.getFromExpectedPayTime());
        queryWrapper.lambda().le(supplierOrderSystemStampDutyPageReq.getToExpectedPayTime() != null, SupplierOrder::getExpectedPayTime, supplierOrderSystemStampDutyPageReq.getToExpectedPayTime());
        queryWrapper.lambda().eq(supplierOrderSystemStampDutyPageReq.getVerifyStatus() != null, SupplierOrder::getVerifyStatus, supplierOrderSystemStampDutyPageReq.getVerifyStatus());
        queryWrapper.lambda().eq(supplierOrderSystemStampDutyPageReq.getReserveStatus() != null, SupplierOrder::getReserveStatus, supplierOrderSystemStampDutyPageReq.getReserveStatus());
        queryWrapper.lambda().eq(supplierOrderSystemStampDutyPageReq.getProductType() != null, SupplierOrder::getProductType, supplierOrderSystemStampDutyPageReq.getProductType());
        queryWrapper.lambda().eq(supplierOrderSystemStampDutyPageReq.getSubmitSettleStatus() != null, SupplierOrder::getSubmitSettleStatus, supplierOrderSystemStampDutyPageReq.getSubmitSettleStatus());
        queryWrapper.lambda().orderByDesc(SupplierOrder::getGmtCreate);
        //do something缺少销售字段查询
        Page<SupplierOrder> iPage = supplierOrderMapper.selectPage(supplierOutsideOrderAirPage, queryWrapper);
        List<SupplierOrder> records = iPage.getRecords();
        if (CollectionUtils.isEmpty(records)) {
            return new PageResponse<>(new ArrayList<>(), iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
        }
        List<SupplierOrderStampDutyPageDTO> supplierOutsideOrderAirQueryDTOList = EntityUtil.copyList(records, SupplierOrderStampDutyPageDTO.class);
        for (SupplierOrderStampDutyPageDTO supplierOrderStampDutyPageDTO : supplierOutsideOrderAirQueryDTOList) {
            UserDTO userDTO = sysUserService.queryCacheUser(supplierOrderStampDutyPageDTO.getCreateId());
            supplierOrderStampDutyPageDTO.setCreateUser(userDTO.getCreateDept());
        }
        return new PageResponse<>(supplierOutsideOrderAirQueryDTOList, iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
    }

    @Override
    public Result<String> addSystemStampDuty(SupplierOrderSystemStampDutyAddReq supplierOrderSystemStampDutyAddReq, Long userId) {
        log.info("【供应商预订-新增系统印花税】入参:{},用户ID:{}", JSON.toJSONString(supplierOrderSystemStampDutyAddReq), userId);
        ValidatorUtil.validate(supplierOrderSystemStampDutyAddReq);
        SupplierOrder supplierOrder = EntityUtil.copy(supplierOrderSystemStampDutyAddReq, SupplierOrder.class);
        LocalDateTime nowDateTime = LocalDateTime.now();

        // 构建供应商预订单-供应商数据
        buildSystemSupplier(supplierOrder, nowDateTime);
        // 构建供应商预订单-状态数据
        buildSupplierBookingOrder(supplierOrder, SupplierReserveTypeEnum.STAMP_DUTY);
        /**
         * 构建内部挂账供应商预订单
         */
        supplierOrder.setReserveStatus(OrderScheduledStatus.RESERVE_SUCCESS.getCode());
        saveInnerSupplierOrder(supplierOrder, userId, nowDateTime);
        saveSupplierOrder(userId, nowDateTime, supplierOrder);
        supplierSystemOrderStampDutyService.add(supplierOrder.getId(), userId, nowDateTime, supplierOrderSystemStampDutyAddReq.getSupplierSystemOrderStampDutyAddReqList());
        return Result.success(supplierOrder.getOrderNumber());
    }

    @Override
    public SupplierOrderSystemStampDutyInfoDTO getSystemStampDuty(Long id) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(id);
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_HOTEL_13501);
        }
        List<SupplierSystemOrderStampDutyInfoDTO> supplierSystemOrderStampDutyCheckInInfoDTOList = supplierSystemOrderStampDutyService.selectByOrderId(id);
        SupplierOrderSystemStampDutyInfoDTO supplierOrderSystemStampDutyInfoDTO = EntityUtil.copy(supplierOrder, SupplierOrderSystemStampDutyInfoDTO.class);
        supplierOrderSystemStampDutyInfoDTO.setSupplierSystemOrderStampDutyInfoDTOList(supplierSystemOrderStampDutyCheckInInfoDTOList);
        return supplierOrderSystemStampDutyInfoDTO;
    }

    @Override
    public PageResponse<SupplierOrderAirExpressPageDTO> selectSystemAirExpressList(SupplierOrderSystemAirExpressPageReq supplierOrderSystemAirExpressPageReq) {
        Page<SupplierOrder> supplierOutsideOrderAirPage = new Page<>(supplierOrderSystemAirExpressPageReq.getPageNo(), supplierOrderSystemAirExpressPageReq.getPageSize());
        QueryWrapper<SupplierOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SupplierOrder::getReserveTypeId, SupplierReserveTypeEnum.AIR_EXPRESS.getId());
        queryWrapper.lambda().eq(SupplierOrder::getBusinessType, SystemBusinessType.AIR_EXPRESS.getCode());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemAirExpressPageReq.getOrderNumber()), SupplierOrder::getOrderNumber, supplierOrderSystemAirExpressPageReq.getOrderNumber());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemAirExpressPageReq.getSaleNumber()), SupplierOrder::getSaleNumber, supplierOrderSystemAirExpressPageReq.getSaleNumber());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemAirExpressPageReq.getSupplierName()), SupplierOrder::getSupplierName, supplierOrderSystemAirExpressPageReq.getSupplierName());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemAirExpressPageReq.getProductName()), SupplierOrder::getProductName, supplierOrderSystemAirExpressPageReq.getProductName());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemAirExpressPageReq.getProductNumber()), SupplierOrder::getProductNumber, supplierOrderSystemAirExpressPageReq.getProductNumber());
        queryWrapper.lambda().ge(supplierOrderSystemAirExpressPageReq.getFromGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderSystemAirExpressPageReq.getFromGmtCreate());
        queryWrapper.lambda().le(supplierOrderSystemAirExpressPageReq.getToGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderSystemAirExpressPageReq.getToGmtCreate());
        queryWrapper.lambda().ge(supplierOrderSystemAirExpressPageReq.getFromExpectedPayTime() != null, SupplierOrder::getExpectedPayTime, supplierOrderSystemAirExpressPageReq.getFromExpectedPayTime());
        queryWrapper.lambda().le(supplierOrderSystemAirExpressPageReq.getToExpectedPayTime() != null, SupplierOrder::getExpectedPayTime, supplierOrderSystemAirExpressPageReq.getToExpectedPayTime());
        queryWrapper.lambda().eq(supplierOrderSystemAirExpressPageReq.getVerifyStatus() != null, SupplierOrder::getVerifyStatus, supplierOrderSystemAirExpressPageReq.getVerifyStatus());
        queryWrapper.lambda().eq(supplierOrderSystemAirExpressPageReq.getReserveStatus() != null, SupplierOrder::getReserveStatus, supplierOrderSystemAirExpressPageReq.getReserveStatus());
        queryWrapper.lambda().eq(supplierOrderSystemAirExpressPageReq.getProductType() != null, SupplierOrder::getProductType, supplierOrderSystemAirExpressPageReq.getProductType());
        queryWrapper.lambda().eq(supplierOrderSystemAirExpressPageReq.getSubmitSettleStatus() != null, SupplierOrder::getSubmitSettleStatus, supplierOrderSystemAirExpressPageReq.getSubmitSettleStatus());
        queryWrapper.lambda().orderByDesc(SupplierOrder::getGmtCreate);
        //do something缺少销售字段查询
        Page<SupplierOrder> iPage = supplierOrderMapper.selectPage(supplierOutsideOrderAirPage, queryWrapper);
        List<SupplierOrder> records = iPage.getRecords();
        if (CollectionUtils.isEmpty(records)) {
            return new PageResponse<>(new ArrayList<>(), iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
        }
        List<SupplierOrderAirExpressPageDTO> supplierOrderAirExpressPageDTOList = EntityUtil.copyList(records, SupplierOrderAirExpressPageDTO.class);
        for (SupplierOrderAirExpressPageDTO supplierOrderAirExpressPageDTO : supplierOrderAirExpressPageDTOList) {
            UserDTO userDTO = sysUserService.queryCacheUser(supplierOrderAirExpressPageDTO.getCreateId());
            supplierOrderAirExpressPageDTO.setCreateUser(userDTO.getCreateDept());
        }
        return new PageResponse<>(supplierOrderAirExpressPageDTOList, iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
    }

    @Override
    public Result<Long> addSystemAirExpress(SupplierOrderSystemAirExpressAddReq supplierOrderSystemAirExpressAddReq, Long userId) {
        log.info("【供应商预订-新增系统机场快线】入参:{},用户ID:{}", JSON.toJSONString(supplierOrderSystemAirExpressAddReq), userId);
        ValidatorUtil.validate(supplierOrderSystemAirExpressAddReq);
        LocalDateTime nowDateTime = LocalDateTime.now();
        SupplierOrder supplierOrder = EntityUtil.copy(supplierOrderSystemAirExpressAddReq, SupplierOrder.class);

        // 构建供应商预订单-供应商数据
        buildSystemSupplier(supplierOrder, nowDateTime);
        // 构建供应商预订单-状态数据
        buildSupplierBookingOrder(supplierOrder, SupplierReserveTypeEnum.AIR_EXPRESS);
        /**
         * 构建内部挂账供应商预订单
         */
        supplierOrder.setReserveStatus(OrderScheduledStatus.RESERVE_SUCCESS.getCode());
        saveInnerSupplierOrder(supplierOrder, userId, nowDateTime);
        saveSupplierOrder(userId, nowDateTime, supplierOrder);
        supplierSystemOrderAirExpressInfoService.add(supplierOrder.getId(), userId, nowDateTime, supplierOrderSystemAirExpressAddReq.getSupplierSystemOrderAirExpressAddReq());
        return Result.success(supplierOrder.getId());
    }

    /**
     * 保存和构建,供应商预订单
     *
     * @param supplierOrder
     * @param supplierReserveType
     */
    private void buildSupplierBookingOrder(SupplierOrder supplierOrder, SupplierReserveTypeEnum supplierReserveType) {
        supplierOrder.setVerifyStatus(SupplierVerifyStatusEnum.UNREADY_VERIFY.getCode()); //未对账
        supplierOrder.setPayStatus(OrderPaymentStatus.UN_PAYMENT.getCode());
        /**
         * 旅行团走审批，自由行走预订
         */
        if (SystemBusinessType.getGroupList().contains(supplierOrder.getBusinessType())) {
            /**
             * 旅行团，生成审批状态
             */
            supplierOrder.setCheckStatus(SupplierCheckStatus.WAIT_CHECK.getCode());
            // 构建供应商内部挂账预订单
            if (supplierOrder.getScheduleId() != null) {
                supplierOrder.setOrderType(1);//订单类型
                supplierOrder.setCheckStatus(SupplierCheckStatus.CHECK_SUCCESS.getCode());
//                supplierOrder.setVerifyStatus(SupplierVerifyStatusEnum.UNREADY_VERIFY.getCode());
//                supplierOrder.setPayStatus(SupplierPaymentStatus.UNREADY_PAY.getCode());
            }
        } else if (SystemBusinessType.getSingleList().contains(supplierOrder.getBusinessType())) {
            /**
             * 自由行，生成预订状态
             * API产品、人工-立即确认产品直接通过,
             * 人工-二次确认产品、外挂单-后台出票产品需供应商预订二次确认
             * 外挂单-门店出票产品需业务模块二次确认
             */
            supplierOrder.setReserveTypeId(supplierReserveType.getId());
            supplierOrder.setReserveTypeName(supplierReserveType.getName());
            supplierOrder.setSubmitSettleStatus(2); // 提交结算状态:2未提交
            if (ProductType.API_PRODUCT.getCode().equals(supplierOrder.getProductType())) {
                //API
                supplierOrder.setReserveStatus(OrderScheduledStatus.RESERVE_SUCCESS.getCode());
            }/* else if (ProductType.MANUAL_ENTRY.getCode().equals(supplierOrder.getProductType())) {
                //人工
                supplierOrder.setReserveStatus(OrderScheduledStatus.CONFIRM_RESERVE.getCode());
            } else if (ProductType.PLUG.getCode().equals(supplierOrder.getProductType())) {
                //外挂
                if (PluginTicketMode.STORE_TICKET.getCode().equals(ticketMode)) {
                    supplierOrder.setReserveStatus(OrderScheduledStatus.RESERVE_SUCCESS.getCode());
                } else if (PluginTicketMode.BACKSTAGE_TICKET.getCode().equals(ticketMode)) {
                    supplierOrder.setReserveStatus(OrderScheduledStatus.CONFIRM_RESERVE.getCode());
                }
            }*/
        }
    }

    private void saveInnerSupplierOrder(SupplierOrder supplierOrder, Long userId, LocalDateTime nowDateTime) {
        if (PayRefundMethod.NAC.getId().equals(supplierOrder.getPayTypeId()) && supplierOrder.getScheduleId() != null) {
            SupplierOrder supplierOrderInner = new SupplierOrder();
            supplierOrderInner.setId(SnowflakeIdWorker.nextId());
            supplierOrderInner.setOrderType(1);//订单类型
            supplierOrderInner.setCheckStatus(SupplierCheckStatus.CHECK_SUCCESS.getCode());
            supplierOrderInner.setSupplierId(supplierOrder.getSupplierId());//供应商ID
            supplierOrderInner.setSupplierName(supplierOrder.getSupplierName());//供应商ID
            supplierOrderInner.setBusinessType(supplierOrder.getBusinessType());//业务类型
            supplierOrderInner.setReserveTypeId(supplierOrder.getReserveTypeId());//预订类型
            supplierOrderInner.setPayableAmount(supplierOrder.getPayableAmount());//应付金额
            supplierOrderInner.setStandardAmount(supplierOrder.getStandardAmount());//本位币金额
            supplierOrderInner.setVerifyStatus(SupplierVerifyStatusEnum.UNREADY_VERIFY.getCode());
            supplierOrderInner.setPayStatus(SupplierPaymentStatus.UNREADY_PAY.getCode());
            supplierOrderInner.setScheduleId(supplierOrder.getScheduleId());//团期ID
            supplierOrderInner.setResourceNumber(supplierOrder.getResourceNumber());//资源编号
            supplierOrderInner.setResourceProductName(supplierOrder.getResourceProductName());//资源产品名称
            supplierOrderInner.setOrderNumber(generatorOrderNumber(nowDateTime));
            supplierOrderInner.setCreateId(userId);
            supplierOrderInner.setGmtCreate(nowDateTime);
            supplierOrderInner.setModifiedId(userId);
            supplierOrderInner.setGmtModified(nowDateTime);
            supplierOrderInner.setIsDeleted(IsDeletedCode.NO.getCode());
            supplierOrderMapper.insert(supplierOrderInner);
        }
    }

    @Override
    public SupplierOrderSystemAirExpressInfoDTO getSystemAirExpress(Long id) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(id);
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_HOTEL_13501);
        }
        List<SupplierSystemOrderAirExpressInfoDTO> supplierSystemOrderAirExpressCheckInInfoDTOList = supplierSystemOrderAirExpressInfoService.selectByOrderId(id);
        SupplierOrderSystemAirExpressInfoDTO supplierOrderSystemAirExpressInfoDTO = EntityUtil.copy(supplierOrder, SupplierOrderSystemAirExpressInfoDTO.class);
        supplierOrderSystemAirExpressInfoDTO.setSupplierSystemOrderAirExpressInfoDTOList(supplierSystemOrderAirExpressCheckInInfoDTOList);
        return supplierOrderSystemAirExpressInfoDTO;
    }

    @Override
    public PageResponse<SupplierOrderVisaPageDTO> selectSystemVisaList(SupplierOrderSystemVisaPageReq supplierOrderSystemVisaPageReq) {
        Page<SupplierOrder> supplierOutsideOrderAirPage = new Page<>(supplierOrderSystemVisaPageReq.getPageNo(), supplierOrderSystemVisaPageReq.getPageSize());
        QueryWrapper<SupplierOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SupplierOrder::getReserveTypeId, SupplierReserveTypeEnum.VISA.getId());
        queryWrapper.lambda().eq(SupplierOrder::getBusinessType, SystemBusinessType.VISA.getCode());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemVisaPageReq.getOrderNumber()), SupplierOrder::getOrderNumber, supplierOrderSystemVisaPageReq.getOrderNumber());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemVisaPageReq.getSaleNumber()), SupplierOrder::getSaleNumber, supplierOrderSystemVisaPageReq.getSaleNumber());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemVisaPageReq.getSupplierName()), SupplierOrder::getSupplierName, supplierOrderSystemVisaPageReq.getSupplierName());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemVisaPageReq.getProductName()), SupplierOrder::getProductName, supplierOrderSystemVisaPageReq.getProductName());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemVisaPageReq.getProductNumber()), SupplierOrder::getProductNumber, supplierOrderSystemVisaPageReq.getProductNumber());
        queryWrapper.lambda().ge(supplierOrderSystemVisaPageReq.getFromGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderSystemVisaPageReq.getFromGmtCreate());
        queryWrapper.lambda().le(supplierOrderSystemVisaPageReq.getToGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderSystemVisaPageReq.getToGmtCreate());
        queryWrapper.lambda().ge(supplierOrderSystemVisaPageReq.getFromExpectedPayTime() != null, SupplierOrder::getExpectedPayTime, supplierOrderSystemVisaPageReq.getFromExpectedPayTime());
        queryWrapper.lambda().le(supplierOrderSystemVisaPageReq.getToExpectedPayTime() != null, SupplierOrder::getExpectedPayTime, supplierOrderSystemVisaPageReq.getToExpectedPayTime());
        queryWrapper.lambda().eq(supplierOrderSystemVisaPageReq.getVerifyStatus() != null, SupplierOrder::getVerifyStatus, supplierOrderSystemVisaPageReq.getVerifyStatus());
        queryWrapper.lambda().eq(supplierOrderSystemVisaPageReq.getReserveStatus() != null, SupplierOrder::getReserveStatus, supplierOrderSystemVisaPageReq.getReserveStatus());
        queryWrapper.lambda().eq(supplierOrderSystemVisaPageReq.getProductType() != null, SupplierOrder::getProductType, supplierOrderSystemVisaPageReq.getProductType());
        queryWrapper.lambda().eq(supplierOrderSystemVisaPageReq.getSubmitSettleStatus() != null, SupplierOrder::getSubmitSettleStatus, supplierOrderSystemVisaPageReq.getSubmitSettleStatus());
        queryWrapper.lambda().orderByDesc(SupplierOrder::getGmtCreate);
        //do something缺少销售字段查询
        Page<SupplierOrder> iPage = supplierOrderMapper.selectPage(supplierOutsideOrderAirPage, queryWrapper);
        List<SupplierOrder> records = iPage.getRecords();
        if (CollectionUtils.isEmpty(records)) {
            return new PageResponse<>(new ArrayList<>(), iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
        }
        List<SupplierOrderVisaPageDTO> supplierOutsideOrderAirQueryDTOList = EntityUtil.copyList(records, SupplierOrderVisaPageDTO.class);
        for (SupplierOrderVisaPageDTO supplierOrderVisaPageDTO : supplierOutsideOrderAirQueryDTOList) {
            UserDTO userDTO = sysUserService.queryCacheUser(supplierOrderVisaPageDTO.getCreateId());
            supplierOrderVisaPageDTO.setCreateUser(userDTO.getCreateDept());
        }
        return new PageResponse<>(supplierOutsideOrderAirQueryDTOList, iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
    }

    @Override
    public Result<Long> addSystemVisa(SupplierOrderSystemVisaAddReq supplierOrderSystemVisaAddReq, Long userId) {
        log.info("【供应商预订-新增系统签证】入参:{},用户ID:{}", JSON.toJSONString(supplierOrderSystemVisaAddReq), userId);
        ValidatorUtil.validate(supplierOrderSystemVisaAddReq);
        SupplierOrder supplierOrder = EntityUtil.copy(supplierOrderSystemVisaAddReq, SupplierOrder.class);
        LocalDateTime nowDateTime = LocalDateTime.now();

        // 构建供应商预订单-供应商数据
        buildSystemSupplier(supplierOrder, nowDateTime);
        // 构建供应商预订单-状态数据
        buildSupplierBookingOrder(supplierOrder, SupplierReserveTypeEnum.VISA);
        /**
         * 构建内部挂账供应商预订单
         */
        supplierOrder.setReserveStatus(OrderScheduledStatus.CONFIRM_RESERVE.getCode());
        saveInnerSupplierOrder(supplierOrder, userId, nowDateTime);
        saveSupplierOrder(userId, nowDateTime, supplierOrder);
        supplierSystemOrderVisaService.add(supplierOrder.getId(), userId, nowDateTime, supplierOrderSystemVisaAddReq.getSupplierSystemOrderVisaAddReqList());
        return Result.success(supplierOrder.getId());
    }

    @Override
    public Result<Long> editSystemVisa(SupplierOrderSystemVisaEditReq supplierOrderSystemVisaEditReq, Long userId) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(supplierOrderSystemVisaEditReq.getId());
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_HOTEL_13501);
        }
        LocalDateTime nowDateTime = LocalDateTime.now();
        supplierOrder.setModifiedId(userId);
        supplierOrder.setGmtModified(nowDateTime);
        updateSystemOrder(supplierOrder);
        supplierSystemOrderVisaService.update(userId, nowDateTime, supplierOrderSystemVisaEditReq.getSupplierSystemOrderVisaEditReqList());
        return Result.success(supplierOrderSystemVisaEditReq.getId());
    }

    @Override
    public SupplierOrderSystemVisaInfoDTO getSystemVisa(Long id) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(id);
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_HOTEL_13501);
        }
        List<SupplierSystemOrderVisaInfoDTO> supplierSystemOrderVisaCheckInInfoDTOList = supplierSystemOrderVisaService.selectByOrderId(id);
        SupplierOrderSystemVisaInfoDTO supplierOrderSystemVisaInfoDTO = EntityUtil.copy(supplierOrder, SupplierOrderSystemVisaInfoDTO.class);
        supplierOrderSystemVisaInfoDTO.setSupplierSystemOrderVisaInfoDTOList(supplierSystemOrderVisaCheckInInfoDTOList);
        return supplierOrderSystemVisaInfoDTO;
    }

    @Override
    public PageResponse<SupplierOrderLocalFunPageDTO> selectSystemLocalFunList(SupplierOrderSystemLocalFunPageReq supplierOrderSystemLocalFunPageReq) {
        Page<SupplierOrder> supplierOutsideOrderAirPage = new Page<>(supplierOrderSystemLocalFunPageReq.getPageNo(), supplierOrderSystemLocalFunPageReq.getPageSize());
        QueryWrapper<SupplierOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SupplierOrder::getReserveTypeId, SupplierReserveTypeEnum.LOCAL_FUN.getId());
        queryWrapper.lambda().eq(SupplierOrder::getBusinessType, SystemBusinessType.LOCAL_FUN.getCode());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemLocalFunPageReq.getOrderNumber()), SupplierOrder::getOrderNumber, supplierOrderSystemLocalFunPageReq.getOrderNumber());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemLocalFunPageReq.getSaleNumber()), SupplierOrder::getSaleNumber, supplierOrderSystemLocalFunPageReq.getSaleNumber());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemLocalFunPageReq.getSupplierName()), SupplierOrder::getSupplierName, supplierOrderSystemLocalFunPageReq.getSupplierName());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemLocalFunPageReq.getProductName()), SupplierOrder::getProductName, supplierOrderSystemLocalFunPageReq.getProductName());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemLocalFunPageReq.getProductNumber()), SupplierOrder::getProductNumber, supplierOrderSystemLocalFunPageReq.getProductNumber());
        queryWrapper.lambda().ge(supplierOrderSystemLocalFunPageReq.getFromGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderSystemLocalFunPageReq.getFromGmtCreate());
        queryWrapper.lambda().le(supplierOrderSystemLocalFunPageReq.getToGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderSystemLocalFunPageReq.getToGmtCreate());
        queryWrapper.lambda().ge(supplierOrderSystemLocalFunPageReq.getFromExpectedPayTime() != null, SupplierOrder::getExpectedPayTime, supplierOrderSystemLocalFunPageReq.getFromExpectedPayTime());
        queryWrapper.lambda().le(supplierOrderSystemLocalFunPageReq.getToExpectedPayTime() != null, SupplierOrder::getExpectedPayTime, supplierOrderSystemLocalFunPageReq.getToExpectedPayTime());
        queryWrapper.lambda().eq(supplierOrderSystemLocalFunPageReq.getVerifyStatus() != null, SupplierOrder::getVerifyStatus, supplierOrderSystemLocalFunPageReq.getVerifyStatus());
        queryWrapper.lambda().eq(supplierOrderSystemLocalFunPageReq.getReserveStatus() != null, SupplierOrder::getReserveStatus, supplierOrderSystemLocalFunPageReq.getReserveStatus());
        queryWrapper.lambda().eq(supplierOrderSystemLocalFunPageReq.getProductType() != null, SupplierOrder::getProductType, supplierOrderSystemLocalFunPageReq.getProductType());
        queryWrapper.lambda().eq(supplierOrderSystemLocalFunPageReq.getSubmitSettleStatus() != null, SupplierOrder::getSubmitSettleStatus, supplierOrderSystemLocalFunPageReq.getSubmitSettleStatus());
        queryWrapper.lambda().orderByDesc(SupplierOrder::getGmtCreate);
        //do something缺少销售字段查询
        Page<SupplierOrder> iPage = supplierOrderMapper.selectPage(supplierOutsideOrderAirPage, queryWrapper);
        List<SupplierOrder> records = iPage.getRecords();
        if (CollectionUtils.isEmpty(records)) {
            return new PageResponse<>(new ArrayList<>(), iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
        }
        List<SupplierOrderLocalFunPageDTO> supplierOutsideOrderAirQueryDTOList = EntityUtil.copyList(records, SupplierOrderLocalFunPageDTO.class);
        for (SupplierOrderLocalFunPageDTO supplierOrderLocalFunPageDTO : supplierOutsideOrderAirQueryDTOList) {
            UserDTO userDTO = sysUserService.queryCacheUser(supplierOrderLocalFunPageDTO.getCreateId());
            supplierOrderLocalFunPageDTO.setCreateUser(userDTO.getCreateDept());
        }
        return new PageResponse<>(supplierOutsideOrderAirQueryDTOList, iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
    }

    @Override
    public Result<Long> addSystemLocalFun(SupplierOrderSystemLocalFunAddReq supplierOrderSystemLocalFunAddReq, Long userId) {
        log.info("【供应商预订-新增系统本地玩乐】入参:{},用户ID:{}", JSON.toJSONString(supplierOrderSystemLocalFunAddReq), userId);
        ValidatorUtil.validate(supplierOrderSystemLocalFunAddReq);
        SupplierOrder supplierOrder = EntityUtil.copy(supplierOrderSystemLocalFunAddReq, SupplierOrder.class);
        LocalDateTime nowDateTime = LocalDateTime.now();

        // 构建供应商预订单-供应商数据
        buildSystemSupplier(supplierOrder, nowDateTime);
        // 构建供应商预订单-状态数据
        buildSupplierBookingOrder(supplierOrder, SupplierReserveTypeEnum.LOCAL_FUN);
        /**
         * 构建内部挂账供应商预订单
         */
        saveInnerSupplierOrder(supplierOrder, userId, nowDateTime);
        saveSupplierOrder(userId, nowDateTime, supplierOrder);
        supplierSystemOrderLocalFunService.add(supplierOrder.getId(), userId, nowDateTime, supplierOrderSystemLocalFunAddReq.getSupplierSystemOrderLocalFunAddReqList());
        return Result.success(supplierOrder.getId());
    }

    @Override
    public Result<Long> editSystemLocalFun(SupplierOrderSystemLocalFunEditReq supplierOrderSystemLocalFunEditReq, Long userId) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(supplierOrderSystemLocalFunEditReq.getId());
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_HOTEL_13501);
        }
        LocalDateTime nowDateTime = LocalDateTime.now();
        supplierOrder.setModifiedId(userId);
        supplierOrder.setGmtModified(nowDateTime);
        updateSystemOrder(supplierOrder);
        supplierSystemOrderLocalFunService.update(userId, nowDateTime, supplierOrderSystemLocalFunEditReq.getSupplierSystemOrderLocalFunEditReqList());
        return Result.success(supplierOrderSystemLocalFunEditReq.getId());
    }

    /**
     * 编辑系统供应商预订-更新供应商预订数据
     *
     * @param supplierOrder
     */
    private void updateSystemOrder(SupplierOrder supplierOrder) {
        supplierOrderMapper.update(new SupplierOrder(), new UpdateWrapper<SupplierOrder>().lambda()
                .eq(SupplierOrder::getId, supplierOrder.getId())
                .set(SupplierOrder::getSupplierContactName, supplierOrder.getSupplierContactName())
                .set(SupplierOrder::getSupplierContactMobileAreaCode, supplierOrder.getSupplierContactMobileAreaCode())
                .set(SupplierOrder::getSupplierContactMobile, supplierOrder.getSupplierContactMobile())
                .set(SupplierOrder::getSupplierContactEmail, supplierOrder.getSupplierContactEmail())
                .set(SupplierOrder::getSupplierContactFax, supplierOrder.getSupplierContactFax())
                .set(SupplierOrder::getOurContactName, supplierOrder.getOurContactName())
                .set(SupplierOrder::getOurContactMobileAreaCode, supplierOrder.getOurContactMobileAreaCode())
                .set(SupplierOrder::getOurContactMobile, supplierOrder.getOurContactMobile())
                .set(SupplierOrder::getOurContactEmail, supplierOrder.getOurContactEmail())
                .set(SupplierOrder::getOurContactFax, supplierOrder.getOurContactFax())
                .set(SupplierOrder::getCurrencyId, supplierOrder.getCurrencyId())
                .set(SupplierOrder::getCurrency, supplierOrder.getCurrency())
                .set(SupplierOrder::getPayType, supplierOrder.getPayType())
                .set(SupplierOrder::getExpectedPayTime, supplierOrder.getExpectedPayTime())
                .set(SupplierOrder::getFilesJson, supplierOrder.getFilesJson())
                .set(SupplierOrder::getRemark, supplierOrder.getRemark())
                .set(SupplierOrder::getModifiedId, supplierOrder.getModifiedId())
                .set(SupplierOrder::getGmtModified, supplierOrder.getGmtModified()));
    }

    @Override
    public SupplierOrderSystemLocalFunInfoDTO getSystemLocalFun(Long id) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(id);
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_HOTEL_13501);
        }
        List<SupplierSystemOrderLocalFunInfoDTO> supplierSystemOrderLocalFunCheckInInfoDTOList = supplierSystemOrderLocalFunService.selectByOrderId(id);
        SupplierOrderSystemLocalFunInfoDTO supplierOrderSystemLocalFunInfoDTO = EntityUtil.copy(supplierOrder, SupplierOrderSystemLocalFunInfoDTO.class);
        supplierOrderSystemLocalFunInfoDTO.setSupplierSystemOrderLocalFunInfoDTOList(supplierSystemOrderLocalFunCheckInInfoDTOList);
        return supplierOrderSystemLocalFunInfoDTO;
    }

    @Override
    public PageResponse<SupplierOrderCommodityPageDTO> selectSystemCommodityList(SupplierOrderSystemCommodityPageReq supplierOrderSystemCommodityPageReq) {
        Page<SupplierOrder> supplierOutsideOrderAirPage = new Page<>(supplierOrderSystemCommodityPageReq.getPageNo(), supplierOrderSystemCommodityPageReq.getPageSize());
        QueryWrapper<SupplierOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SupplierOrder::getReserveTypeId, SupplierReserveTypeEnum.COMMODITY.getId());
        queryWrapper.lambda().eq(SupplierOrder::getBusinessType, SystemBusinessType.COMMODITY.getCode());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemCommodityPageReq.getOrderNumber()), SupplierOrder::getOrderNumber, supplierOrderSystemCommodityPageReq.getOrderNumber());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemCommodityPageReq.getSaleNumber()), SupplierOrder::getSaleNumber, supplierOrderSystemCommodityPageReq.getSaleNumber());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemCommodityPageReq.getSupplierName()), SupplierOrder::getSupplierName, supplierOrderSystemCommodityPageReq.getSupplierName());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemCommodityPageReq.getProductName()), SupplierOrder::getProductName, supplierOrderSystemCommodityPageReq.getProductName());
        queryWrapper.lambda().like(StringUtils.isNotBlank(supplierOrderSystemCommodityPageReq.getProductNumber()), SupplierOrder::getProductNumber, supplierOrderSystemCommodityPageReq.getProductNumber());
        queryWrapper.lambda().ge(supplierOrderSystemCommodityPageReq.getFromGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderSystemCommodityPageReq.getFromGmtCreate());
        queryWrapper.lambda().le(supplierOrderSystemCommodityPageReq.getToGmtCreate() != null, SupplierOrder::getGmtCreate, supplierOrderSystemCommodityPageReq.getToGmtCreate());
        queryWrapper.lambda().ge(supplierOrderSystemCommodityPageReq.getFromExpectedPayTime() != null, SupplierOrder::getExpectedPayTime, supplierOrderSystemCommodityPageReq.getFromExpectedPayTime());
        queryWrapper.lambda().le(supplierOrderSystemCommodityPageReq.getToExpectedPayTime() != null, SupplierOrder::getExpectedPayTime, supplierOrderSystemCommodityPageReq.getToExpectedPayTime());
        queryWrapper.lambda().eq(supplierOrderSystemCommodityPageReq.getVerifyStatus() != null, SupplierOrder::getVerifyStatus, supplierOrderSystemCommodityPageReq.getVerifyStatus());
        queryWrapper.lambda().eq(supplierOrderSystemCommodityPageReq.getReserveStatus() != null, SupplierOrder::getReserveStatus, supplierOrderSystemCommodityPageReq.getReserveStatus());
        queryWrapper.lambda().eq(supplierOrderSystemCommodityPageReq.getProductType() != null, SupplierOrder::getProductType, supplierOrderSystemCommodityPageReq.getProductType());
        queryWrapper.lambda().eq(supplierOrderSystemCommodityPageReq.getSubmitSettleStatus() != null, SupplierOrder::getSubmitSettleStatus, supplierOrderSystemCommodityPageReq.getSubmitSettleStatus());
        queryWrapper.lambda().orderByDesc(SupplierOrder::getGmtCreate);
        //do something缺少销售字段查询
        Page<SupplierOrder> iPage = supplierOrderMapper.selectPage(supplierOutsideOrderAirPage, queryWrapper);
        List<SupplierOrder> records = iPage.getRecords();
        if (CollectionUtils.isEmpty(records)) {
            return new PageResponse<>(new ArrayList<>(), iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
        }
        List<SupplierOrderCommodityPageDTO> supplierOutsideOrderAirQueryDTOList = EntityUtil.copyList(records, SupplierOrderCommodityPageDTO.class);
        for (SupplierOrderCommodityPageDTO supplierOrderCommodityPageDTO : supplierOutsideOrderAirQueryDTOList) {
            UserDTO userDTO = sysUserService.queryCacheUser(supplierOrderCommodityPageDTO.getCreateId());
            supplierOrderCommodityPageDTO.setCreateUser(userDTO.getCreateDept());
        }
        return new PageResponse<>(supplierOutsideOrderAirQueryDTOList, iPage.getCurrent() == 1, iPage.getTotal() <= (iPage.getCurrent() * iPage.getSize()), iPage.getTotal(), iPage.getCurrent(), iPage.getSize());
    }

    @Override
    public Result<Long> addSystemCommodity(SupplierOrderSystemCommodityAddReq supplierOrderSystemCommodityAddReq, Long userId) {
        log.info("【供应商预订-新增系统商品】入参:{},用户ID:{}", JSON.toJSONString(supplierOrderSystemCommodityAddReq), userId);
        ValidatorUtil.validate(supplierOrderSystemCommodityAddReq);
        SupplierOrder supplierOrder = EntityUtil.copy(supplierOrderSystemCommodityAddReq, SupplierOrder.class);
        LocalDateTime nowDateTime = LocalDateTime.now();

        // 构建供应商预订单-供应商数据
        buildSystemSupplier(supplierOrder, nowDateTime);
        // 构建供应商预订单-状态数据
        buildSupplierBookingOrder(supplierOrder, SupplierReserveTypeEnum.COMMODITY);
        /**
         * 构建内部挂账供应商预订单
         */
        saveInnerSupplierOrder(supplierOrder, userId, nowDateTime);
        saveSupplierOrder(userId, nowDateTime, supplierOrder);
        supplierSystemOrderCommodityService.add(supplierOrder.getId(), userId, nowDateTime, supplierOrderSystemCommodityAddReq.getSupplierSystemOrderCommodityAddReqList());
        return Result.success(supplierOrder.getId());
    }

    @Override
    public Result<Long> editSystemCommodity(SupplierOrderSystemCommodityEditReq supplierOrderSystemCommodityEditReq, Long userId) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(supplierOrderSystemCommodityEditReq.getId());
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_HOTEL_13501);
        }
        LocalDateTime nowDateTime = LocalDateTime.now();
        supplierOrder.setModifiedId(userId);
        supplierOrder.setGmtModified(nowDateTime);
        updateSystemOrder(supplierOrder);
        supplierSystemOrderCommodityService.update(userId, nowDateTime, supplierOrderSystemCommodityEditReq.getSupplierSystemOrderCommodityEditReqList());
        return Result.success(supplierOrderSystemCommodityEditReq.getId());
    }

    @Override
    public SupplierOrderSystemCommodityInfoDTO getSystemCommodity(Long id) {
        SupplierOrder supplierOrder = supplierOrderMapper.selectById(id);
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_OUT_HOTEL_13501);
        }
        List<SupplierSystemOrderCommodityInfoDTO> supplierSystemOrderCommodityCheckInInfoDTOList = supplierSystemOrderCommodityService.selectByOrderId(id);
        SupplierOrderSystemCommodityInfoDTO supplierOrderSystemCommodityInfoDTO = EntityUtil.copy(supplierOrder, SupplierOrderSystemCommodityInfoDTO.class);
        supplierOrderSystemCommodityInfoDTO.setSupplierSystemOrderCommodityInfoDTOList(supplierSystemOrderCommodityCheckInInfoDTOList);
        return supplierOrderSystemCommodityInfoDTO;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result systemConfirm(SupplierOrderSystemConfirmReq supplierOrderSystemConfirmReq, Long userId) {
        log.info("【供应商预订单-系统业务二次确认】方法入参:{},userId:{}", JSON.toJSONString(supplierOrderSystemConfirmReq), userId);
        SupplierOrder supplierOrder = supplierOrderMapper.selectOne(new QueryWrapper<SupplierOrder>().lambda()
                .eq(SupplierOrder::getId, supplierOrderSystemConfirmReq.getId())
                .eq(SupplierOrder::getIsDeleted, IsDeletedCode.NO.getCode()));
        if (null == supplierOrder) {
            throw new BusinessException(SystemError.SYS_411);
        }
        if (Objects.equals(SupplierConfirmStatus.CONFIRMED.getCode(), supplierOrder.getConfirmStatus())) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_13701);
        }
        LocalDateTime nowDateTime = LocalDateTime.now();
        // 调用自由行-更新状态
        supplierOrderMapper.update(null, new UpdateWrapper<SupplierOrder>().lambda()
                .eq(SupplierOrder::getId, supplierOrder.getId())
                .set(SupplierOrder::getReserveStatus, supplierOrderSystemConfirmReq.getReserveStatus())
                .set(SupplierOrder::getSupplierOrderNumber, supplierOrderSystemConfirmReq.getSupplierOrderNumber())
                .set(SupplierOrder::getFilesJson, supplierOrderSystemConfirmReq.getFilesJson())
                .set(SupplierOrder::getConfirmStatus, SupplierConfirmStatus.CONFIRMED.getCode()) // 已确认
                .set(SupplierOrder::getConfirmTime, nowDateTime)
                .set(SupplierOrder::getModifiedId, userId)
                .set(SupplierOrder::getGmtModified, nowDateTime));
        Result result = null;
        SystemConfirmReq systemConfirmReq = new SystemConfirmReq();
        systemConfirmReq.setSaleNumber(supplierOrderSystemConfirmReq.getSaleNumber());
        systemConfirmReq.setReserveStatus(supplierOrderSystemConfirmReq.getReserveStatus());
        SystemBusinessType systemBusinessType = SystemBusinessType.parseCode(supplierOrder.getBusinessType());
        switch (systemBusinessType) {
            case HOTEL:
                log.info("【供应商预订单-系统业务二次确认】调用酒店入参:{},userId:{}", JSON.toJSONString(systemConfirmReq), userId);
                result = hotelOrderCenterService.supplierConfirmOrder(systemConfirmReq.getSaleNumber(), systemConfirmReq.getReserveStatus(), userId);
                break;
            case AIR_TICKET:
                log.info("【供应商预订单-系统业务二次确认】调用机票入参:{},userId:{}", JSON.toJSONString(systemConfirmReq), userId);
                result = airOrderService.supplierConfirmOrder(
                        SupplierConfirmOrderReq.builder()
                                .saleNumber(systemConfirmReq.getSaleNumber())
                                .reserveStatus(systemConfirmReq.getReserveStatus()).build(),
                        userId);
                break;
            case TRAIN_TICKET:
                log.info("【供应商预订单-系统业务二次确认】调用火车票入参:{},userId:{}", JSON.toJSONString(systemConfirmReq), userId);
//                result = trainOrderService.supplierConfirmOrder(systemConfirmReq, userId);
                break;
            case BUS_TICKET:
                BusOrderSupplieConfirmReq busOrderSupplieConfirmReq = new BusOrderSupplieConfirmReq();
                busOrderSupplieConfirmReq.setSaleNumber(supplierOrderSystemConfirmReq.getSaleNumber());
                busOrderSupplieConfirmReq.setReserveStatus(supplierOrderSystemConfirmReq.getReserveStatus());
                log.info("【供应商预订单-系统业务二次确认】调用巴士入参:{},userId:{}", JSON.toJSONString(busOrderSupplieConfirmReq), userId);
                result = busOrderService.supplieConfirmOrder(busOrderSupplieConfirmReq, userId);
                break;
            case SHIP_TICKET:
//                log.info("【供应商预订单-系统业务二次确认】调用船票入参:{},userId:{}", JSON.toJSONString(systemConfirmReq), userId);
//                result = shipOrderService.supplierConfirmOrder(systemConfirmReq, userId);
                break;
            case ATTRACTION_TICKET:
                ConfirmProductTickeReq confirmProductTickeReq = new ConfirmProductTickeReq();
                confirmProductTickeReq.setSaleNumber(systemConfirmReq.getSaleNumber());
                confirmProductTickeReq.setConfirmType(systemConfirmReq.getReserveStatus());
                List<ProductTicketDTO> ticketList = JSON.parseArray(supplierOrderSystemConfirmReq.getTicketNumberJSON(), ProductTicketDTO.class);
                confirmProductTickeReq.setProductTicketDTO(ticketList);
                log.info("【供应商预订单-系统业务二次确认】调用景点门票入参:{},userId:{}", JSON.toJSONString(confirmProductTickeReq), userId);
                result = scenicOrderService.supplierConfirmOrder(confirmProductTickeReq);
                break;
            case LOCAL_FUN:
                result = localFunOrderService.supplierConfirmOrder(systemConfirmReq, userId);//当地玩乐没有外挂单-门店下单
                break;
            case VISA:
                VisaOrderSupplieConfirmReq visaOrderSupplieConfirmReq = new VisaOrderSupplieConfirmReq();
                visaOrderSupplieConfirmReq.setSaleNumber(systemConfirmReq.getSaleNumber());
                if (Objects.equals(systemConfirmReq.getReserveStatus(), OrderScheduledStatus.RESERVE_SUCCESS.getCode())) {
                    visaOrderSupplieConfirmReq.setReserveStatus(5);
                } else if (Objects.equals(systemConfirmReq.getReserveStatus(), OrderScheduledStatus.RESERVE_FAIL.getCode())) {
                    visaOrderSupplieConfirmReq.setReserveStatus(6);
                }
                log.info("【供应商预订单-系统业务二次确认】调用签证入参:{},userId:{}", JSON.toJSONString(visaOrderSupplieConfirmReq), userId);
                result = visaOrderService.supplieConfirmOrder(visaOrderSupplieConfirmReq, userId);
                break;
            default:
                Result.failed(SystemError.SYS_437);
        }
        if (null == result || !result.isSuccess()) {
            return Result.failed(SystemError.SYS_437);
        }
        return Result.success();
    }

    @Override
    public Result freeCallSystemConfirm(SupplierOrderSystemFreeCallConfirmReq supplierOrderSystemFreeCallConfirmReq, Long userId) {
        log.info("【供应商预订单-自由行业务门市下单】方法入参:{},userId:{}", JSON.toJSONString(supplierOrderSystemFreeCallConfirmReq), userId);
        SupplierOrder supplierOrder = supplierOrderMapper.selectSourceBySaleNumber(supplierOrderSystemFreeCallConfirmReq.getSaleNumber());
        if (supplierOrder == null) {
            throw new BusinessException(SystemError.SYS_411);
        }
        if (Objects.equals(SupplierConfirmStatus.CONFIRMED.getCode(), supplierOrder.getConfirmStatus())) {
            throw new BusinessException(SystemError.SUPPLIER_BOOKING_13701);
        }
        LocalDateTime nowDateTime = LocalDateTime.now();
        supplierOrderMapper.update(null, new UpdateWrapper<SupplierOrder>().lambda()
                .eq(SupplierOrder::getId, supplierOrder.getId())
                .set(SupplierOrder::getReserveStatus, OrderScheduledStatus.RESERVE_SUCCESS.getCode())
                .set(SupplierOrder::getSupplierOrderNumber, supplierOrderSystemFreeCallConfirmReq.getSupplierOrderNumber())
                .set(SupplierOrder::getFilesJson, supplierOrderSystemFreeCallConfirmReq.getFilesJson())
                .set(SupplierOrder::getConfirmStatus, SupplierConfirmStatus.CONFIRMED.getCode())
                .set(SupplierOrder::getConfirmTime, nowDateTime)
                .set(SupplierOrder::getModifiedId, userId)
                .set(SupplierOrder::getGmtModified, nowDateTime));
        return Result.success();
    }

    @Override
    public Result<List<SupplierOrderFinanceListDTO>> queryFinanceListByScheduleId(Long scheduleId, Long userId) {
        log.info("【供应商预订单-根据团期ID查询供应商预订单和财务数据列表】方法入参, data:{}, userId:{}", scheduleId, userId);
        List<SupplierOrderFinanceListDTO> supplierOrderFinanceListDTOList = supplierOrderMapper.selectObjs(new QueryWrapper<SupplierOrder>().lambda()
                .eq(SupplierOrder::getSupplierId, scheduleId)
                .eq(SupplierOrder::getIsDeleted, IsDeletedCode.NO.getCode())
                .select(SupplierOrder::getOrderNumber, SupplierOrder::getSupplierName, SupplierOrder::getCreateId,
                        SupplierOrder::getReserveStatus, SupplierOrder::getPayStatus)).stream().map(o -> (SupplierOrderFinanceListDTO) o).collect(Collectors.toList());
        Result<List<SupplierReconciliationAmountDTO>> financeListResult = financeSupplierReconciliationService.getByOrderIdList(supplierOrderFinanceListDTOList.stream().map(o -> o.getId()).collect(Collectors.toList()));
        if (!financeListResult.isSuccess()) {
            log.error("【供应商预订单-根据团期ID查询供应商预订单和财务数据列表】查询失败, data{}", JSON.toJSONString(financeListResult));
        }
        log.info("【供应商预订单-根据团期ID查询供应商预订单和财务数据列表】查询结果, data{}", JSON.toJSONString(financeListResult));
        List<SupplierReconciliationAmountDTO> financeList = financeListResult.getData();
        supplierOrderFinanceListDTOList.forEach(supplier -> {
            for (SupplierReconciliationAmountDTO finance : financeList) {
                if (Objects.equals(supplier.getId(), finance.getOrderId())) {
                    supplier.setPayStatus(finance.getPayStatus());
                    supplier.setPayableAmount(finance.getPayableAmount());
                    supplier.setPaidAmount(finance.getPayableAmount());
                    supplier.setUnPayAmount(finance.getUnPayAmount());
                    break;
                }
            }
        });
        return Result.success(supplierOrderFinanceListDTOList);
    }

    /**
     * 根据币种ID获取汇率，获取汇率, 供应商预订仅使用计划汇率
     *
     * @return
     */
    private BigDecimal getPlanExchangeRateById(Long currencyId) {
        MainDataCurrencyUpdateStatusReq mainDataCurrencyUpdateStatusReq = new MainDataCurrencyUpdateStatusReq();
        mainDataCurrencyUpdateStatusReq.setId(currencyId);
        log.info("【供应商预订-查询汇率】request:{}", JSON.toJSONString(mainDataCurrencyUpdateStatusReq));
        Result<MainDataCurrencyQueryDTO> queryCurrencyRateResult = mainDataCurrencyService.query(mainDataCurrencyUpdateStatusReq);
        log.info("【供应商预订-查询汇率】exchange rate result:{}", JSON.toJSONString(queryCurrencyRateResult));
        if (!queryCurrencyRateResult.isSuccess()) {
            SystemError defined = SystemError.getDefined(queryCurrencyRateResult.getCode());
            throw new BusinessException(defined);
        }
        MainDataCurrencyQueryDTO data = queryCurrencyRateResult.getData();
        if (data == null) {
            throw new BusinessException(SystemError.SYS_411);
        }
        return data.getPlannedExchangeRate();
    }

}
